Register to reply

Rotating objects in x y and z

by DaveC426913
Tags: objects, rotating
Share this thread:
DaveC426913
#1
Nov28-08, 09:20 AM
DaveC426913's Avatar
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 shrink-wrapped 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 end-on 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...
Phys.Org News Partner Science news on Phys.org
Sapphire talk enlivens guesswork over iPhone 6
Geneticists offer clues to better rice, tomato crops
UConn makes 3-D copies of antique instrument parts
D H
#2
Nov28-08, 01:06 PM
Mentor
P: 15,065
First things first: It takes a minimum of three parameters to describe a rotation in three-space, not two. Pick up a book. Rotating the book by say 45 degrees about an axis normal to
  1. The cover of the book
  2. The top edge of the book
  3. The right edge of the book
  4. Some other non-principal axis
will yield different orientations. There are three rotational degrees of freedom in 3-space. For 4-space there are six rotational degrees of freedom. In generalized N-space, there are N*(N-1)/2 rotational degrees of freedom.


Rotations, in any dimension, have the following characteristics:
  1. Leaving an object unrotated is a null rotation of the object. Mathematically, rotation has an identity element.
  2. You can undo any rotation. Mathematically, every rotation has an inverse.
  3. If you rotate an object in some way and then rotate in some other way, the result is still a rotation of the object. Mathematically, rotation is a closed operation.
  4. Suppose you rotate an object 3 times: rotation a followed by rotation b followed by rotation c. Since rotation is closed, with can denote a•b to denote the end result of performing rotation a followed by rotation b, and b•c as the end result of performing rotation b followed by rotation c. So, what happens when you do rotations a then b then c? Is the result (a•b)•c or a•(b•c)? The answer is "yes". (a•b)•c = a•(b•c). Mathematically, rotation is transitive.
You can view rotation as a mathematical operator on the orientation of object. From above, there is an identity rotation, every rotation has an inverse, and rotation is closed and transitive. These are the attributes of a mathematical group. Rotation is such an important group that it has a name: SO(n), where n is the dimensionality of the space. That SO means "special orthogonal". I'll get to that later. You are interested in SO(3).

There are many different ways to represent rotations in 3-space. A few of them are
  • Rotation matrices. The rotation group is called the special orthogonal group because a rotation in N-space can be described by a NxN matrix, but not just any random NxN matrix. Only NxN matrices (a) have a determinant of 1 ("special") and (b) whose inverse is equal to the transpose of the matrix ("orthogonal") describe a proper rotation, and all matrices that have these two characteristics describe a rotation. This is true for rotations in any dimension, not just three. This general characteristic is why the n-dimensional rotation group is called SO(n).

  • Euler angles. This is a sequence of three rotations about three pre-specified axes. (Remember that it takes a minimum of three parameters to describe a rotation). Which pre-specified axes depends on who you talk to. Astronomers use a rotation about the z axis, followed by a second rotation about the rotated x axis, followed by a third rotation about the doubly-rotated z axis. In short, a z-x-z rotation sequence. Aerospace engineers use some permutation of rotations about the x, y, and z axes, such as an x-y-z rotation sequence or a z-y-x rotation sequence; there are six such permutations altogether. Euler angles, whatever form you choose to use, are evil.

  • Eigen rotations.
  • Unit quaternions.
  • Rodrigues parameters.
  • Modified Rodrigues parameters.
  • ...
Please read this wikipedia article on rotation matrices, and then come back with questions.


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 X-Y grid lines (e.g., graph paper) and a transparent sheet of plastic similarly printed with X-Y 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 X-Y 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.
DaveC426913
#3
Nov29-08, 10:26 AM
DaveC426913's Avatar
P: 15,319
Quote Quote by D H View Post
First things first: It takes a minimum of three parameters to describe a rotation in three-space, not two.
Where did I say two parameters? You misunderstood what I wrote.

I actually said six:
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.
But ultimately, it is only displayed in two dimensions:
I'm going to end up with two equations, x=... and y=...
So, again, I'll have two equations (i,e, two outputs : x and y screen coords) that will have 6 parameters as input.

Much of the rest of what you say seems to be based on that initial misunderstanding.

Note that, ultimately, I'm representing objects in 2-space.

D H
#4
Nov29-08, 01:12 PM
Mentor
P: 15,065
Rotating objects in x y and z

Quote Quote by DaveC426913 View Post
Where did I say two parameters? You misunderstood what I wrote.
Sorry about that.

Much of the rest of what you say seems to be based on that initial misunderstanding.
Now you are the one misunderstanding. My post has four sections: (1) degrees of freedom in a rotation in N-space, (2) rotation forms a mathematical group, (3) there are many different ways to represent rotations in 3-space, and (4) difference between rotation and transformation. Only the first part, which comprises the first paragraph of my post, pertains to that original misunderstanding.
DaveC426913
#5
Nov30-08, 12:24 AM
DaveC426913's Avatar
P: 15,319
Quote Quote by D H View Post
Now you are the one misunderstanding. My post has four sections: (1) degrees of freedom in a rotation in N-space, (2) rotation forms a mathematical group, (3) there are many different ways to represent rotations in 3-space, and (4) difference between rotation and transformation. Only the first part, which comprises the first paragraph of my post, pertains to that original misunderstanding.
Well, I mean I don't really see how that will get me to my goal.

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.
D H
#6
Nov30-08, 04:14 PM
Mentor
P: 15,065
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
  • the x-axis is horizontal, positive to the right,
  • the y-axis is vertical, positive upward,
  • vectors are expressed as column vectors, and
  • rotation is positive counterclockwise.
Expressed as a column vector, the vector from the origin to [itex](x,y)[/itex] is

[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 N-space
Suppose you have three reference frames in some N-space 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_{n-1} \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 right-to-left extends to all dimensions. Since rotation is the transpose of transformation, rotation matrices chain left-to-right.

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 3-space
Rotation/transformation in 2-space is much easier to comprehend than in 3-space. Obviously, a rotation or transformation matrix for a vector in 3-space in 3-space 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 3-space. 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,
  • You will have to post-multiply a vector by a rotation or transformation matrix to form a rotated or transformed vector.
  • The rotation matrix for a row vector is the transpose of the rotation matrix for a column vector; the same is true for transformation matrices.
  • Rotation matrices for row vectors chain right-to-left and transformation matrices for row vectors chain left-to-right.


Last words
My wife has the last word. She wants me to stop playing and do some silly house chores.
DaveC426913
#7
Nov30-08, 04:28 PM
DaveC426913's Avatar
P: 15,319
Hm. Well, you lost me right about
Quote Quote by D H View Post
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
  • the x-axis is horizontal, positive to the right,
  • the y-axis is vertical, positive upward,
  • vectors are expressed as column vectors, and
  • rotation is positive counterclockwise.
Expressed as a column vector, the vector from the origin to [itex](x,y)[/itex] is

[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].
here.

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 post-secondary education, I'm afraid the representation on paper is beyond me. I guess I'm in over my head.
DaveC426913
#8
Dec2-08, 09:19 AM
DaveC426913's Avatar
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.
Attached Thumbnails
PF20081202_XYZplot.gif  


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 non-inertial frames Introductory Physics Homework 1
Current around rotating objects? General Physics 3