Finding a general rotation in 3D

edited March 2020 in Assignments

(10 pts)

In this problem, you're going to find a matrix $M$ that represents rotation through a randomly generated angle about a randomly generated vector.

First, use the Python code here to find your angle and vector. Do be sure to replace where you see 'first_name_here' with your first name and then hit evaluate.

Then, find your matrix using the following strategy:

First, find an orthogonal matrix $S$ that maps $\vec{\imath} = \langle 1,0,0 \rangle$ to your randomly generated vector and also maps $\vec{\jmath}$ and $\vec{k}$ to a pair of unit vectors that are perpendicular to one another, as well as to your vector. Of course, the way to do that is to simply choose the columns of $S$ to be the vectors in question.

Next, find a matrix $R$ that represents rotation through the angle $t$ about the $x$-axis.

Finally, I guess your matrix should be $M = S\cdot R \cdot S^{-1}$.

Your answer should consist of three parts:

  • The matrix $S$,
  • The matrix $R$, and
  • The matrix $M$.

Feel free to perform all computational parts with the computer and report the results here.

Comments

  • dandan
    edited April 2020

    My sage serve code gave me: "Share
    Find a matrix M representing rotation through the angle
    1.25 radians about the vector [2 2 1];' after inputting: "dan"

    I choose my S simply to be a matrix where:
    1.) unit vector $\overrightarrow{i} $ by the matrix produces <2,2,1>
    2.) The other columns are orthogonal to that first column.
    3.) That each collom vector is normalized.

    So I went with

    $$
    S=
    \begin{bmatrix}
    \frac{2]}{\sqrt{5}} & \frac{-1}{\sqrt{2}} & \frac{1}{2} \\
    \frac{2}{\sqrt{5}} & \frac{1}{\sqrt{2}} & \frac{1}{2} \\
    \frac{1}{\sqrt{5}} & 0 & -1
    \end{bmatrix}
    $$

    Using spicy.linalg.inv: I got the inverse of that matrix $$S^{-1}$$

    S = np.array([
    [2/np.sqrt(5),-1/np.sqrt(2),.5],
    [2/np.sqrt(5),1/np.sqrt(2),.5],
    [1/np.sqrt(5),0,-1]
     ])
    
    T = inv(S)
    print(T)
    
    #out
    [[ 0.4472136   0.4472136   0.4472136 ]
    [-0.70710678  0.70710678  0.        ]
    [ 0.2         0.2        -0.8       ]]
    

    note $T = S^{-1}$, because I didn't want to put that in python.
    Than I double checked they worked:

    S.dot(T)
    
    #out:
    array([[ 1.00000000e+00,  2.77555756e-17,  0.00000000e+00],
       [-2.77555756e-17,  1.00000000e+00,  0.00000000e+00],
       [-2.77555756e-17,  0.00000000e+00,  1.00000000e+00]])
    

    Which seams on the money (ignoring floating point error)

    Finally we need matrix R which is given simply as the 3D rotation matrix around the x axis:

    $$
    R_x(\theta)=
    \begin{bmatrix}
    1 & 0 & 0 \\
    0 & \cos(\theta) & -\sin(\theta) \\
    0 & \sin(\theta) & \cos(\theta)
    \end{bmatrix}
    $$

    In my case theta is in Rads and that is 1.25. Putting that into Python:

    R = np.array([
    [1,0,0],
    [0,np.cos(1.25),-np.sin(1.25)],
    [0,np.sin(1.25),np.cos(1.25)]
    ])
    

    Than using python to sum that all together such that $ M = SRS^{-1}$

    M = S.dot(R.dot(T))
    print(M)
    
    #out: 
    [[ 0.38788338  0.74359448 -0.26295571]
    [-0.19585237  0.79050346  0.81069782]
    [ 0.80796899 -0.53409793  0.45225789]]
    
  • edited April 2020

    @dan I think you made some good progress here. Don't forget, though, that the columns of an orthogonal matrix must be unit vectors (as well as mutually orthogonal).

    Also, I made a few adjustments on your LaTeX code.

  • The vector I got is,

    $\begin{pmatrix}
    1 & 2 & 1
    \end{pmatrix}$
    

    From the way the problem is described above, it seems like the S matrix I should use is

    $\begin{pmatrix}
    1 & 0 & 0 \\
    2 & 1 & 0 \\
    1 & 0 & 1
    \end{pmatrix}$
    

    But this is not an orthogonal matrix because S*S transpose doesn't equal the identity matrix. Anyways, I'll just go ahead and start the process here.

    The rotation matrix should be the following since the angle I got was 6.06 radians.

    $\begin{pmatrix}
    1 & 0 & 0 \\
    0 & 0.975 & -0.106 \\
    0 & 0.106 & 0.975
    \end{pmatrix}$
    

    And using np.linalg.inv() I got S inverse,

    import numpy as np
    m1=np.array([[1,0,0],[2,1,0],[1,0,1]])
    np.linalg.inv(m1)
    

    which output the following.

    $\begin{pmatrix}
    1 & 0 & 0 \\
    -2 & 1 & 0 \\
    -1 & 0 & 1
    \end{pmatrix}$
    

    So we can then use this to compute M.

    $\begin{pmatrix}
    1 & -4.703 & -1.379 \\
    2.427 & 1 & 1.817 \\
    1.286 & -1.663 & 1
    \end{pmatrix}$
    
  • edited April 2020

    


Using the name PrinceHumperdinck with the given code the following vector and angle were generated 3.95 radians about the vector [3 3 1]
    Since the first vector isn't changing, it becomes the first vector of matrix $S$ after it has been normalized. In python this is

    s1 = np.array([3,3,1])
    s1 = s1/np.linalg.norm(s1)
    

    Now to find a unit vector orthogonal to $s_1$ I projected an arbitrary vector $a$ onto $s_1$ and subtracted the projection from $a$ with the following code.

    a = np.array([1,0,0])
    s2 = a - (a.dot(s1)/s1.dot(s1))*s1
    

    Next I normalized $s_2$ and used numpy.cross() to compute a vector $s_3$ that is both a unit vector and orthogonal to the first two. Afterwords I put all the vectors into matrix $S$.

    s2 = s2/np.linalg.norm(s2)
    s3 = np.cross(s1,s2)
    s3 = s3/np.linalg.norm(s3)
    S = np.array([
        s1,
        s2,
        s3
    ])
    S = S.transpose()
    

    The final matrix $S$ is

    [[ 0.6882472   0.72547625  0.        ]
     [ 0.6882472  -0.65292863  0.31622777]
     [ 0.22941573 -0.21764288 -0.9486833 ]]
    

    and to verify its orthogonality I multiplied $A^TA$ to get

    [[ 1.00000000e+00 -2.42861287e-16  0.00000000e+00]
     [-2.42861287e-16  1.00000000e+00  0.00000000e+00]
     [ 0.00000000e+00  0.00000000e+00  1.00000000e+00]]
    

    The two non-diagonal elements that are not exactly zero are due to round-off error.
    To form my $R$ and $S^{-1}$ matrices I put my angle of $3.95 radians$ in the general rotation matrix
    $
    R_x(\theta)=
    \begin{bmatrix}
    1 & 0 & 0 \\
    0 & cos(\theta) & -sin(\theta) \\
    0 & sin(\theta) & cos(\theta)
    \end{bmatrix}
    $ and I used numpy.linalg.inv() to compute $S^{-1}$.

    R = np.array([
        [1, 0, 0],
        [0, np.cos(3.95), -np.sin(3.95)],
        [0, np.sin(3.95), np.cos(3.95)]
    ])
    SInv = np.linalg.inv(S)
    

    The output for $R$ is

    [[ 1.          0.          0.        ]
     [ 0.         -0.6906511   0.72318812]
     [ 0.         -0.72318812 -0.6906511 ]]
    

    and $S^{-1}$ is

    [[ 0.6882472   0.6882472   0.22941573]
     [ 0.72547625 -0.65292863 -0.21764288]
     [ 0.          0.31622777 -0.9486833 ]]
    

    Finally multiplying out $SRS^{-1}$ to get M with M = S.dot(R.dot(SInv)) resulted in

    [[ 0.11018363  0.96674546 -0.23078729]
     [ 0.634924    0.11018363  0.76467711]
     [ 0.76467711 -0.23078729 -0.60166946]]
    
    mark
  • edited April 2020
    Find a matrix M representing rotation through the angle
    2.87 radians about the vector [2 3 1].
    

    I'm probably over complicating this, but here's how I did it.

    First, I lined the vector up with the y-axis. To achieve this, I rotated the the vector about the x-axis,
    $$R_{x}=\begin{pmatrix}
    1&0&0\\
    0&-\sqrt{\frac{13}{14}}&\sqrt{\frac{1}{14}}\\
    0&-\sqrt{\frac{1}{14}}&-\sqrt{\frac{13}{14}}\end{pmatrix},$$
    and then about the z-axis,
    $$R_{z}=\begin{pmatrix}
    \frac{3}{\sqrt{13}}&-\frac{2}{\sqrt{13}}&0\\
    \frac{2}{\sqrt{13}}&\frac{3}{\sqrt{13}}&0\\
    0&0&1\end{pmatrix}.$$
    Once, the vector was lined up with the y-axis, I rotated by 2.87 rads,
    $$R_{y}=\begin{pmatrix}
    \cos(2.87)&0&\sin(2.87)\\
    0&1&0\\
    -\sin(2.87)&0&\cos(2.87)\end{pmatrix}$$
    Lastly, I put it all back again so that,
    $$M=R_{x}R_{z}R_{y}R_{z}^{-1}R_{x}^{-1}\approx\begin{pmatrix}
    -0.359&0.933&0.0271\\
    0.814&0.299&0.499\\
    0.457&0.201&-0.866\end{pmatrix}$$

    Here's the Python code:

    import numpy as np
    import math as mt
    from scipy.linalg import inv
    
    st = -1/mt.sqrt(14)
    ct = -mt.sqrt(13)/mt.sqrt(14)
    sg = mt.sin(2.87)
    cg = mt.cos(2.87)
    sa = 2/mt.sqrt(13)
    ca = 3/mt.sqrt(13)
    
    Rx = np.matrix([
        [1,0,0],
        [0,ct,-st],
        [0,st,ct]
    ])
    
    Ry = np.matrix([
        [cg,0,sg],
        [0,1,0],
        [-sg,0,cg]
    ])
    
    Rz = np.matrix([
        [ca,-sa,0],
        [sa,ca,0],
        [0,0,1]
    ])
    
    M = Rx.dot(Rz.dot(Ry.dot(inv(Rz).dot(inv(Rx)))))
    print('M = ', M)
    
    
    Out:
    
    M =  [[-0.35923875  0.93285243  0.02708987]
     [ 0.81354121  0.29880541  0.49886473]
     [ 0.45727258  0.20125027 -0.86625638]]
    
    mark
  • I like @frank's the best so far! Note that I can copy the code to reproduce it and check to see that the matrix is orthogonal and compute the eigenvalues to check the answer super easily.

  • @PrinceHumperdinck I think you're super close here! Note that your first column is not normalized; that's why your matrix isn't quite orthogonal.

  • I corrected my answer by normalizing the first vector in the $S$ matrix.

  • edited April 2020

    I was given a rotation of $\theta = 2.22 \ rad$ about the vector $\vec{v} = [ 4 \ \ 1 \ \ 1 ]$.

    I began by determining the orthogonal matrix, S, using the Gram-Schmidt process.

    $$
    \vec{w}_1 =
    \begin{bmatrix}
    4\\
    1\\
    1
    \end{bmatrix} \ , \ \ \vec{w}_2 =
    \begin{bmatrix}
    0\\
    1\\
    0
    \end{bmatrix} \ , \ \ \vec{w}_3 =
    \begin{bmatrix}
    0\\
    0\\
    1
    \end{bmatrix}
    $$

    $$\vec{v}_1 = \vec{w}_1$$

    $$\vec{v}_2 = \vec{w}_2 - \frac{\langle w_2 , v_1 \rangle}{\langle v_1 , v_1 \rangle} \vec{v}_1$$

    $$\vec{v}_3 = \vec{w}_3 - \frac{\langle w_3 , v_1 \rangle}{\langle v_1 , v_1 \rangle} \vec{v}_1 - \frac{\langle w_3 , v_2 \rangle}{\langle v_2 , v_2 \rangle} \vec{v}_2$$

    Skipping over the math, the orthogonal set of vectors came out to be (after normalizing $\vec{v}_1$),

    $$
    \vec{v}_1 =
    \begin{bmatrix}
    \frac{2 \sqrt{2}}{3}\\
    \frac{\sqrt{2}}{6}\\
    \frac{\sqrt{2}}{6}
    \end{bmatrix} \ , \ \ \vec{v}_2 =
    \begin{bmatrix}
    -\frac{2}{9}\\
    \frac{17}{18}\\
    -\frac{1}{18}
    \end{bmatrix} \ , \ \ \vec{v}_3 =
    \begin{bmatrix}
    -\frac{4}{17}\\
    0\\
    \frac{16}{17}
    \end{bmatrix}
    $$

    Which produces the orthogonal matrix,

    $$
    S = (\vec{v}_1 \ \vec{v}_2 \ \vec{v}_3) = \begin{pmatrix}
    \frac{2 \sqrt{2}}{6} & -\frac{2}{9} & -\frac{4}{17}\\
    \frac{\sqrt{2}}{6} & \frac{17}{18} & 0\\
    \frac{\sqrt{2}}{6} & -\frac{1}{18} & \frac{16}{17}
    \end{pmatrix}
    $$

    I used python for the rest of the problem, starting with verifying that $S^{-1} = S^{T}$.

    import math
    import numpy as np
    from scipy.linalg import inv
    
    S = np.array([
        [(math.sqrt(2)/(1.5)), -(2/9), -(4/17)],
        [(math.sqrt(2)/6), (17/18), 0],
        [(math.sqrt(2)/6), -(1/18), (16/17)]
    ])
    
    S_inv = inv(S)
    S_t = S.transpose()
    
    print(S_inv)
    print()
    print(S_t)
    
    
    # out
    [[ 0.94280904  0.23570226  0.23570226]
     [-0.23529412  1.         -0.05882353]
     [-0.25        0.          1.        ]]
    
    [[ 0.94280904  0.23570226  0.23570226]
     [-0.22222222  0.94444444 -0.05555556]
     [-0.23529412  0.          0.94117647]]
    

    As you can see, the entries in $S^{-1}$ and $S^{T}$ differ slightly; however, these differences seem to be small enough to dismiss as rounding errors.

    Next, I determined the rotation matrix, R, using the general rotation matrix about the x-axis,

    $$
    R_{x}(\theta) = \begin{pmatrix}
    1 & 0 & 0\\
    0 & cos(\theta) & -sin(\theta)\\
    0 & sin(\theta) & cos(\theta)
    \end{pmatrix}
    $$

    R = np.array([
        [1, 0, 0],
        [0, math.cos(2.22), -(math.sin(2.22))],
        [0, math.sin(2.22), math.cos(2.22)]
    ])
    

    Lastly, I determined $M$,

    $$M = SRS^{-1}$$

    M = S.dot(R.dot(S_inv))
    print(M)
    
    # out
    [[ 0.82156329  0.16914     0.54460685]
     [ 0.54464513 -0.51541048 -0.66317004]
     [ 0.16910172  0.83885047 -0.51525735]]
    

    As a simple check, I verified that the vector being rotated about was unchanged under the transformation.

    v = np.array([4, 1, 1])
    M.dot(v)
    
    # out
    array([4., 1., 1.])
    
    mark
  • edited April 2020

    Oddly, I got the same problem as joshua, with $\theta = 2.22 $ the vector $v= \begin{pmatrix}4 \\ 1 \\ 1 \end{pmatrix} $.

    I used python for almost every step of this problem, starting with importing the right libraries and defining some data.

    import numpy as np
    from scipy.linalg import inv
    
    vec = np.matrix([4,1,1]).transpose()
    theta = 2.22
    i = np.matrix([1,0,0]).transpose()
    j = np.matrix([0,1,0]).transpose()
    k = np.matrix([0,0,1]).transpose()
    

    I also wrote a couple little functions to help myself out:

    #defines the projection of v2 onto v1
    def proj(v1, v2):
        top = v2.transpose().dot(v1).item()
        bottom = v1.transpose().dot(v1).item()
        return (top/bottom)*v1
    
    #normalize a vector
    def normalize(vec):
        return vec/np.linalg.norm(vec)
    

    Next, I used the Gram-Schmidt process to change vec, j, and k into an orthogonal set and then normalized each vector.

    x1 = vec
    x2 = j - proj(x1,j)
    x3 = k - proj(x1,k) - proj(x2,k)
    
    x1 = normalize(x1)
    x2 = normalize(x2)
    x3 = normalize(x3)
    

    I used these vectors as the columns for the matrix S, then used inv to compute S_inv, and checked to ensure that S is orthonormal:

    S = np.append(np.append(x1,x2,1),x3,1)
    S_inv = inv(S)
    print(S_inv-S.transpose())
    #output:
    #[[-1.11022302e-16 -2.77555756e-17 -5.55111512e-17]
     #[-2.77555756e-17  1.11022302e-16 -6.93889390e-18]
     #[ 0.00000000e+00  0.00000000e+00  0.00000000e+00]]
    

    Since most people would consider all of those numbers to be zero, we'll call that a success.
    I then created the rotation matrix R, defining a rotation of angle $\theta$ about the x axis.

    R = np.matrix([
        [1,0,0],
        [0,np.cos(theta),-np.sin(theta)],
        [0,np.sin(theta), np.cos(theta)]
    ])
    

    Finally, I computed $M = S \cdot R \cdot S^{-1}$

    M = S.dot(R).dot(S_inv)
    M
    #output:
    #matrix([[ 0.82171641,  0.16881489,  0.54431945],
            #[ 0.54431945, -0.51541048, -0.66186734],
            #[ 0.16881489,  0.84015092, -0.51541048]])
    

    I checked my answer below to ensure that my original vector maps to itself.

    M.dot(vec)
    #output:
    #matrix([[4.],
            #[1.],
            #[1.]])
    
    mark
  • edited April 2020

    The following is the results I got from the provided code:

    #Find a matrix M representing rotation through the angle
    #5.20 radians about the vector [1 2 2].
    

    In order to calculate the M matrix, I used the Gram-Schmidt Process (described on page 193 in our text). The following was the code I used to calculate the matrix and verify the results:

    import numpy as np
    import math as mt
    from scipy.linalg import lu, inv, solve, lu_solve, lu_factor, norm, eig, inv
    
    #Find a matrix M representing rotation through the angle
    #5.20 radians about the vector [1 2 2].
    
    
    # Use the Gram-Schmidt process to find the columns of the S matrix.
    
    # v1:
    theta = 5.20
    
    m = np.array([3,3,1])
    m_norm = m/np.linalg.norm(m)
    v1_T = m/np.linalg.norm(m)
    v1 = v1_T.transpose()
    
    # v2:
    v2_T = n - (n.dot(v1_T)/v1_T.dot(v1_T))*v1_T
    v2_T = v2_T/np.linalg.norm(v2_T)
    v2 = v2_T.transpose()
    
    
    # v3 needs to be orthogonal to v1 and v2. Take the cross product of v1 and v2 to find
    v3_T_ortho = np.cross(v1_T,v2_T)
    v3_T = v3_T_ortho/np.linalg.norm(v3_T_ortho)
    v3 = v3_T.transpose()
    #print(v1)
    # Matrix must be formed before components are transposed due to how arrays are formed
    S_T = np.array([v1_T, v2_T, v3_T ])
    # S_T was transposed to M by hand due to some technical issues.
    S = np.array([
        [0.6882472, 0.72547625, 0],
        [0.6882472, -0.65292863, 0.31622777],
        [0.22941573, -0.21764288, -0.9486833]   
    ])
    
    S_inv = inv(S)
    
    print('\n S_T: ')
    print(S_T)
    print('\n S: ')
    print(S)
    
    # To check, multiply S and S_T to verify the result is the identify matrix
    print('\n S*S_T:')
    print(S.dot(S_T))
    
    print('\n R_x:')
    print(R_x)
    
    # To rotate around the x-axis by a given angle, theta, use the equation below for R_x
    R_x = np.array([
        [1, 0, 0],
        [0, np.cos(theta), -np.sin(theta)],
        [0, np.sin(theta), np.cos(theta)]   
    ])
    
    # Once S, R_x, and S_inv are found, determine M
    M = S.dot(R_x).dot(S_inv)
    
    print('\n M:')
    print(M)
    
    

    The print statements generated the following outputs:


    $ S*S^{T} $ will form the identity matrix, with the values shown above having some rounding errors. After calculating, the following is the matrix M.

    $$
    M \approx \left(
    \begin{array}{cccc}
    0.72027193 & 0.45443366 & -0.52411677 \\
    0.04907687 & 0.72027193 & 0.69195362 \\
    0.69195361 & -0.52411678 & 0.49648948 \\
    \end{array}
    \right).
    $$

    mark
  • edited April 2020

    Using the provided sage cell, my vector and angle are
    $\vec{v} = [2,4,2]^T$ and $\theta = 1.24rad$.
    To determine my $S$ matrix I defined another vector
    $\vec{u} = [ -1,1,-1]^T$. Noticing that $\vec{v}\cdot\vec{u}=0$, the third vector $\vec{w}=\vec{v}\times\vec{u}$ should form an orthogonal basis so my matrix will be $S = (\hat{v},\hat{u},\hat{w})$. Using python, $S$ is given as

    v = array([2, 4, 2])
    u = array([0, 1,-2])
     v_hat = v/norm(v)
    u_hat = u/norm(u)
    w_hat = cross(y1,x1)
    S = transpose(array([v_hat,u_hat,w_hat]))
    print(S)
    #ouput:
    [[ 0.40824829  0.          0.91287093]
    [ 0.81649658  0.4472136  -0.36514837]
    [ 0.40824829 -0.89442719 -0.18257419]]
    

    $$
    S =
    \begin{bmatrix}
    0.40824829 & 0. & 0.91287093\\
    0.81649658 & 0.4472136 & -0.36514837\\
    0.40824829 & -0.89442719 & -0.18257419
    \end{bmatrix}.
    $$
    Since $S$ transforms $\hat{i}$ to $\hat{v}$, I need to use a rotation around the $x$ axis,
    $$
    R_x(\theta) =
    \begin{bmatrix}
    1 & 0 & 0\\
    0 & \cos(\theta) & -\sin(\theta) \\
    0 & \sin(\theta) & \cos(\theta)
    \end{bmatrix}.
    $$
    Again Python provides a numerical answer,

    A = 1.24
    R_x = array([[1,0,0],[0,cos(A),-sin(A)],[0,sin(A), cos(A)]])
    print(R_x)
    #output:
    [[ 1.          0.          0.        ]
    [ 0.          0.32479628 -0.945784  ]
    [ 0.          0.945784    0.32479628]]
    

    $$
    R_x(\theta) =
    \begin{bmatrix}
    1 & 0 & 0\\
    0 & 0.32479628 & -0.945784 \\
    0 & 0.945784 & 0.32479628
    \end{bmatrix}.
    $$
    Finally, the matrix which performs a rotation of $\theta$ around the axis $\vec{v}$ is given as $M = SR_xS^{-1}$, or in numerical form as

    M = S.dot(R_x.dot(inv(S)))
    print(M)
    #output:
    [[ 0.43733024  0.61118261 -0.65969545]
    [-0.1610468   0.77493209  0.61118261]
    [ 0.88476335 -0.1610468   0.43733024]]
    

    $$
    M =
    \begin{bmatrix}
    0.43733024 & 0.61118261 & -0.65969545\\
    -0.1610468 & 0.77493209 & 0.61118261 \\
    0.88476335 & -0.1610468 & 0.43733024
    \end{bmatrix}.
    $$

    mark
  • edited April 2020

    My given vector was $\vec{v}=<3,2,3>$ and rotation was 4.42 rad.
    I began with a vector whose dot product with $\vec{v}$ was equal to 0. That vector was $\vec{w}=<-1,0,1>$. To find a vector who satisfied orthogonality for both $\vec{v}$ and $\vec{w}$ I took the cross product of $\vec{v}$ and $\vec{w}$. That vector was $\vec{z} = <2,-6,2>$. After normalizing each vector, they become the columns of my S matrix, such that

    $ S = \left[ \begin{matrix}
    \frac{3} {\sqrt{22}} & -\frac{1} {\sqrt{2}} & \frac{2} {44} \\
    \frac{2} {\sqrt{22}} & 0 & - \frac{6} {44} \\
    \frac{3} {\sqrt{22}} & \frac{1} {\sqrt{2}} & \frac{2} {44}
    \end{matrix} \right] $

    I used Python to verify that this matrix was orthogonal by multiplying $S^{T}S$, which output

    matrix([[1.00000000e+00, 2.26319396e-17, 5.37650243e-17],
        [2.26319396e-17, 1.00000000e+00, 5.45400326e-18],
        [5.37650243e-17, 5.45400326e-18, 1.00000000e+00]])
    

    I believe because I found these normalizations by hand without using the program, the rounding caused the small decimals off the diagonal, but It suffices to say, without numerical rounding, this S matrix is orthogonal.

    In order to find R, I input

    R=np.matrix([
    [1, 0, 0],
    [0, np.cos(4.42), -np.sin(4.42)],
    [0, np.sin(4.42), np.cos(4.42)]
    ])
    

    and too find M,

    S_inv=inv(S)
    M=S.dot(R.dot(S_inv))
    #output
    [[ 0.2387669   0.96379451  0.11870343]
     [-0.26111781 -0.05401506  0.96379451]
     [ 0.93531164 -0.26111781  0.2387669 ]]
    

    or

    $M=\left[\begin{matrix}
    0.2387669 & 0.96379451 & 0.11870343 \\
    -0.26111781 & -0.05401506 & 0.96379451 \\
    0.93531164 & -0.26111781 & 0.2387669
    \end{matrix}\right]$

    Donkeymark
  • edited April 2020

    For this problem, I will be finding a matrix M representing rotation through the angle 5.16 radians about the vector $ v =<4,2,3>$.

    I will start by finding an orthonormal matrix S , which can be represented by three orthogonal column vectors, given that the first column vector is the normalized version of our vector $v$.

    First, we find that the magnitude of $v = \sqrt{4^2+2^2+3^2} = \sqrt{29}$. Thus, our normalized $v$, $s1$ is the vector $s1 = <\frac{4}{sqrt{29}},\frac{2}{sqrt{29}},\frac{3}{sqrt{29}}>$.

    I then used the following Python code to generate two more orthogonal vectors, $s2$ and $s3$:

    s1 = np.array([4/(29**.5),2/(29**.5),3/(29**.5)])
    i = np.array([1,0,0])
    s2=i - (i.dot(s1)/s1.dot(s1))*s1
    
    s2=s2/np.linalg.norm(s2)
    s3=np.cross(s1,s2)
    s3=s3/np.linalg.norm(s3)
    
    print(s2,s3)
    Out:
    [ 0.66953406 -0.41202096 -0.61803144] [ 0.          0.83205029 -0.5547002 ]
    

    Using these vectors as column vectors of S, we find that

    $$ S = \begin{pmatrix}
    .7428 & .6695 & 0 \\
    .3714 & -.4120 & .8321\\
    .5571 & -.6180 & -.5547
    \end{pmatrix} $$
    We can check this is accurate by verifying that $S^TS=I$.
    S = np.array([
    s1,
    s2,
    s3
    ])
    S=S.transpose()
    print(S.transpose().dot(S))

    Out:
    
    [[ 1.00000000e+00  5.89849729e-17  6.72761352e-17]
     [ 5.89849729e-17  1.00000000e+00 -7.09001506e-17]
     [ 6.72761352e-17 -7.09001506e-17  1.00000000e+00]]
    

    Thus, S matrix checks out.

    In order to find our R matrix, we simply the use the matrix

    $$ R = \begin{pmatrix}
    1 & 0 & 0 \\
    0 & cos(\theta) & -sin(\theta) \\
    0 & sin(\theta) & cos(\theta)
    \end{pmatrix} $$

    but use $\theta=5.16$. This yields the matrix

    $$ R = \begin{pmatrix}
    1 & 0 & 0 \\
    0 & .4328 & -.9015 \\
    0 & .9015 & .4328
    \end{pmatrix} .$$

    Then to find M, we use $$M=SRS^{-1}.$$

    M = S.dot(R.dot(inv(S)))
    print(M)
    Out:
    [[ 0.74574382  0.65866928 -0.10010462]
     [-0.3457386   0.51104581  0.78695425]
     [ 0.56950063 -0.55225624  0.60883665]]
    

    So we find that

    $$ M = \begin{pmatrix}
    .7457 & .6587 & -.1001 \\
    -.3457 & ..5110 & .7870 \\
    .5695 & -.5523 & .6088
    \end{pmatrix}.$$

    mark
  • elieli
    edited May 2020

    For my example, I got a rotation angle of 3.03 radians and a vector of [1, 2, 2]
    using this I got

    $$ S = \begin{pmatrix}
    .333 & 0 & -.943 \\
    .666 & .707 & .236 \\
    .666 & -.707 & .236
    \end{pmatrix} $$

    Using this I found

    sinv = inv(s)
    sinv
    array([[ 0.33333333,  0.66666667,  0.66666667],
           [-0.        ,  0.70710678, -0.70710678],
           [-0.94280904,  0.23570226,  0.23570226]])
    

    To find R, I simply plugged in 3.03 for theta and got

    R = np.matrix([
        [1,0,0],
        [0, np.cos(3.03), -np.sin(3.03)],
        [0, np.sin(3.03), np.cos(3.03)]
    ])
    R
    matrix([[ 1.        ,  0.        ,  0.        ],
            [ 0.        , -0.99378   , -0.11136119],
            [ 0.        ,  0.11136119, -0.99378   ]])
    

    Finally, I found the transformation matrix

    M = s.dot(R.dot(sinv))
    M
    matrix([[-0.77224889,  0.36882143,  0.51730301],
            [ 0.51730301, -0.10765555,  0.84900405],
            [ 0.36882143,  0.92324484, -0.10765555]])
    
    mark
Sign In or Register to comment.