Register to reply 
Rotating objects in x y and z 
Share this thread: 
#1
Nov2808, 09:20 AM

P: 15,319

My buddy, a Flash developer, wants to learn 3D rotation of objects from first principles, i.e. using trig. I know there are shrinkwrapped engines out there that will do this for you, but he wants to learn it. From me. Cuz I'm the math whiz.
I used to do this simply when I'd plot simple 3D graphs in "Basic classic" but now I'm stepping it up a notch. I'll start off with a primitive object and rotation on one axis. So... my primitive object is a line in the XYZ space. It extends from 0,0,0 to 0,0,100. From my observer PoV, where I can only see the XY plane, the line is seen endon and will appear as a point. Now I rotate my line about the origin by 5 degrees. I know that I've got to do sin(5), which is about .087(x100 = 8.7). So the line is now visible in my XY viewing plane connecting 0 , 0 and 8.7 , 0. Good so far? Ultimately, it seems to me, I'm going to end up with two equations, x=... and y=... where the right side will be a long string of trig functions with x,y and z angles and x,y and z distances as variables. Are there more robust techniques I can use? My buddy talks about multiplying matrices, which I know nothing about (but who knows, maybe I'm a quick learn). And then I've got to add perspective... 


#2
Nov2808, 01:06 PM

Mentor
P: 15,155

First things first: It takes a minimum of three parameters to describe a rotation in threespace, not two. Pick up a book. Rotating the book by say 45 degrees about an axis normal to
Rotations, in any dimension, have the following characteristics:
There are many different ways to represent rotations in 3space. A few of them are
On final note: Very few people make a proper distinction between rotation and transformation. They are distinct but related concepts. The distinction is easily visualizable in 2D. Imagine an opaque sheet of paper printed with XY grid lines (e.g., graph paper) and a transparent sheet of plastic similarly printed with XY grid lines. Mark some point on the graph paper and some point on the transparency; these points will serve as the origins of your graph paper and transparency reference frames. Now mark some other point on the graph paper with a dot. That point has some specific X and Y coordinates in the graph paper reference frame. Now put the plastic transparency on top of the graph paper such that the origins are collocated. Next, rotate the transparency with respect to the graph paper. Finally, determine the transparency frame XY coordinates of the point you marked on the graph paper. The physical rotation of the transparency with respect to the opaque graph paper is just that: a physical rotation. You can describe this rotation in terms of a rotation matrix. The graph paper frame and transparency frame coordinates of that point you marked on the graph paper are related by a transformation matrix from the graph paper frame to the transparency frame. The rotation matrix from the graph paper frame to the transparency frame and the transformation matrix from the graph paper frame to the transparency frame are not the same thing. They are instead transposes of one another. 


#3
Nov2908, 10:26 AM

P: 15,319

I actually said six: Much of the rest of what you say seems to be based on that initial misunderstanding. Note that, ultimately, I'm representing objects in 2space. 


#4
Nov2908, 01:12 PM

Mentor
P: 15,155

Rotating objects in x y and z



#5
Nov3008, 12:24 AM

P: 15,319

Oh. Ah. I see now. I said my guy wants to "learn" this; I realize that was disengenuous. I realize our goal is really to understand the specifiic steps to get us to a workable algorithm. 


#6
Nov3008, 04:14 PM

Mentor
P: 15,155

I'll start with 2D rotation and transformation matrices and extend this to 3D.
Physical rotation of a vector in 2D Suppose you have a vector with cartesian coordinates (x,y) and want to rotate this by some angle theta. I'll use the conventional notations
[tex]\boldsymbol{r} = \bmatrix x\\y\endbmatrix[/tex] The coordinates of the endpoint of the rotated vector are (derivation is an exercise left to the reader) [itex](x\cos\theta  y\sin\theta, x\sin\theta + y\cos\theta)[/itex] or [tex]\boldsymbol{r}' = \bmatrix x\cos\theta  y\sin\theta \\ x\sin\theta + y\cos\theta\endbmatrix = \bmatrix \cos\theta & \sin\theta \\ \sin\theta & \cos\theta \endbmatrix \, \bmatrix x\\y\endbmatrix = \mathbf{R}(\theta) \, \boldsymbol{r}[/tex] where [tex]\mathbf{R}(\theta) \equiv \bmatrix \cos\theta & \sin\theta \\ \sin\theta & \cos\theta \endbmatrix [/tex] is the 2D matrix that physically rotates a column vector by an angle [itex]\theta[/itex]. Transformation of a vector in 2D If you physically rotate the [itex]\hat{\boldsymbol x}[/itex] and [itex]\hat{\boldsymbol x}[/itex] unit vectors by some angle [itex]\theta[/itex] you will get a new coordinate system with unit vectors [itex]\hat{\boldsymbol x}'[/itex] and [itex]\hat{\boldsymbol x}'[/itex]: [tex]\aligned \hat{\boldsymbol x}' &= \mathbf{R}(\theta)\,\hat{\boldsymbol x} \\ \hat{\boldsymbol y}' &= \mathbf{R}(\theta)\,\hat{\boldsymbol y} \endaligned[/tex] Given some point with coordinates [itex](x,y)[/itex] in the original coordinate system, the coordinates of that point in the rotated coordinate system are (derivation once again left to the reader) [itex](x',y') = (x\cos\theta + y\sin\theta, x\sin\theta + y\cos\theta)[/itex] or [tex]\boldsymbol{r}' = \bmatrix x\cos\theta + y\sin\theta \\ x\sin\theta + y\cos\theta\endbmatrix = \bmatrix \cos\theta & \sin\theta \\ \sin\theta & \cos\theta \endbmatrix \, \bmatrix x\\y\endbmatrix = \mathbf{T}(\theta) \, \boldsymbol{r}[/tex] where [tex]\mathbf{T}(\theta) \equiv \bmatrix \cos\theta & \sin\theta \\ \sin\theta & \cos\theta \endbmatrix [/tex] is the 2D matrix that transforms a column vector to the frame physically rotated by an angle [itex]\theta[/itex] with respect to the original frame. In this simple 2D world, the transformation and rotation matrices are obviously related by [itex]\mathbf{T}(\theta) = \mathbf{R}(\theta)[/itex]. A much better way to look at this is that the two are transposes of one another: [itex]\mathbf{T}(\theta) = \mathbf{R}^T(\theta)[/itex]. The reason this is a much better way to look at things is that this transpose relationship holds in higher dimensions. Rotation and translation are conjugate operations. Sequence of transformations in Nspace Suppose you have three reference frames in some Nspace with a common origin but different orientations. I'll denote these as frames A, B, and C. Denote [itex]\boldsymbol{r}_A[/itex], [itex]\boldsymbol{r}_B[/itex], and [itex]\boldsymbol{r}_C[/itex] as the representations of some vector r in these three frames. These representations are related by the transformation matrices from one frame to another: [tex]\aligned \boldsymbol{r}_B &= \mathb{T}_{A \to B} \boldsymbol{r}_A \\ \boldsymbol{r}_C &= \mathb{T}_{A \to C} \boldsymbol{r}_A \\ &= \mathb{T}_{B \to C} \boldsymbol{r}_B \endaligned[/tex] Combining the above, [tex]\aligned \boldsymbol{r}_C &= \mathb{T}_{A \to C} \boldsymbol{r}_A \\ &= \mathb{T}_{B \to C} \boldsymbol{r}_B \\ &= \mathb{T}_{B \to C} (\mathb{T}_{A \to B} \boldsymbol{r}_A) \\ &= (\mathb{T}_{B \to C} \mathb{T}_{A \to B}) \boldsymbol{r}_A \endaligned[/tex] The final step uses the fact that matrix multiplication is transitive. Since the above must be true for any vector r, [tex]\mathb{T}_{A \to C} = \mathb{T}_{B \to C}\,\mathb{T}_{A \to B}[/tex] With an even more rotations chained in a sequence, [tex]\mathbf{T}_{F_1 \to F_n} = \mathbf{T}_{F_{n1} \to F_n},\cdots\,\mathbf{T}_{F_1 \to F_2}[/tex] This result makes no assumptions of the dimensionality of the space. Transformation matrices for column vectors chain from righttoleft extends to all dimensions. Since rotation is the transpose of transformation, rotation matrices chain lefttoright. The order of operations here is very important for any dimension higher than two. Two dimensional transformation (or rotation) matrices commute. For higher dimensions, multiplication of transformation (or rotation) matrices is not commutative. Rotation/Transformation in 3space Rotation/transformation in 2space is much easier to comprehend than in 3space. Obviously, a rotation or transformation matrix for a vector in 3space in 3space is a 3x3 matrix. Constructing or making sense of a 2x2 rotation or transformation matrix is an easy task. One way to construct a 3x3 rotation or transformation matrix is to construct the rotation/transformation as a sequence of simpler rotations/transformations. Euler's rotation theorem will help in this regard. Euler's rotation theorem says that any rotation in three space is a rotation can be expressed as a 2D rotation about some axis in 3space. In particular, the transformation matrices corresponding to rotations about the x, y, and z axes are [tex]\aligned \mathbf{T}_x(\theta) &= \bmatrix 1&0&0 \\ 0&\cos\theta&\sin\theta \\ 0&\sin\theta&\cos\theta \endbmatrix \\ \mathbf{T}_y(\phi) &= \bmatrix \sin\phi&0&\cos\phi \\ 0&1&0 \\ \cos\phi&0&\sin\phi \endbmatrix \\ \mathbf{T}_z(\psi) &= \bmatrix \cos\psi&\sin\psi&0 \\ \sin\psi&\cos\psi&0 \\ 0&0&1 \endbmatrix \endaligned[/tex] While Euler angles are evil, they do serve a very useful purpose in the construction of transformation matrices. Sources of confusion One obvious source of confusion is the distinction between rotation and transformation. I harp on this because they are distinct concepts and because failing to distinguish between these concepts is the source of a lot of errors. In this post, I have use [itex]\boldsymbol R[/itex] to denote a rotation matrix and [itex]\boldsymbol T[/itex] to denote a transformation matrix to avoid confusion. Another source of confusion is whether vectors are expressed as column or row vectors. While column vectors are used more widely than are row vectors, this is just convention. If you instead use a row vector convention,
Last words My wife has the last word. She wants me to stop playing and do some silly house chores. 


#7
Nov3008, 04:28 PM

P: 15,319

Hm. Well, you lost me right about
If I define a point in the 3D space at xyz, and I supply a rotation of xyz, will those equations spit out an xy coordinate for it in the viewing plane? I'm sorry, I have great facility with conceptualizing mathematics but, without a formal postsecondary education, I'm afraid the representation on paper is beyond me. I guess I'm in over my head. 


#8
Dec208, 09:19 AM

P: 15,319

I'm still at it.
My point at 0,0,100, if rotated by 5 degrees about the y axis, will end up at these coords: [tex] x_g = z_{d} sin(y_a) [/tex] [tex] y_g = z_d sin(x_a) [/tex] where  [tex]x_g[/tex] and [tex]y_g[/tex] are the viewing plane XY coords (i.e. the output),  [tex]z_d[/tex] is the distance from origin in the z direction and  [tex]x_a[/tex] and [tex]y_a[/tex] are the x and y angles of rotation, respectively. 


Register to reply 
Related Discussions  
Kinetic energy in rotating objects.  Introductory Physics Homework  1  
Friction between rotating objects  Classical Physics  3  
Why the black objects absorb more light and heat from the other color objects?  General Physics  27  
Rotating objects in noninertial frames  Introductory Physics Homework  1  
Current around rotating objects?  General Physics  3 