Finding a general rotation in 3D
(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
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}$$
note $T = S^{-1}$, because I didn't want to put that in python.
Than I double checked they worked:
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:
Than using python to sum that all together such that $ M = SRS^{-1}$
@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,
From the way the problem is described above, it seems like the S matrix I should use is
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.
And using np.linalg.inv() I got S inverse,
which output the following.
So we can then use this to compute M.
Using the name
PrinceHumperdinck
with the given code the following vector and angle were generated3.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
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.
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$.The final matrix $S$ is
and to verify its orthogonality I multiplied $A^TA$ to get
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}$.The output for $R$ is
and $S^{-1}$ is
Finally multiplying out $SRS^{-1}$ to get M with
M = S.dot(R.dot(SInv))
resulted inI'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:
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.
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}$.
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}
$$
Lastly, I determined $M$,
$$M = SRS^{-1}$$
As a simple check, I verified that the vector being rotated about was unchanged under the transformation.
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.
I also wrote a couple little functions to help myself out:
Next, I used the Gram-Schmidt process to change
vec
,j
, andk
into an orthogonal set and then normalized each vector.I used these vectors as the columns for the matrix
S
, then usedinv
to computeS_inv
, and checked to ensure thatS
is orthonormal: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.Finally, I computed $M = S \cdot R \cdot S^{-1}$
I checked my answer below to ensure that my original vector maps to itself.
The following is the results I got from the provided code:
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:
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).
$$
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
$$
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,
$$
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 =
\begin{bmatrix}
0.43733024 & 0.61118261 & -0.65969545\\
-0.1610468 & 0.77493209 & 0.61118261 \\
0.88476335 & -0.1610468 & 0.43733024
\end{bmatrix}.
$$
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
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
and too find M,
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]$
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$:
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))
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}.$$
So we find that
$$ M = \begin{pmatrix}
.7457 & .6587 & -.1001 \\
-.3457 & ..5110 & .7870 \\
.5695 & -.5523 & .6088
\end{pmatrix}.$$
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
To find R, I simply plugged in 3.03 for theta and got
Finally, I found the transformation matrix