How can I rotate objects in 3D using trigonometry and perspective?

  • Thread starter DaveC426913
  • Start date
  • Tags
    Rotating
In summary: If you turn the sheet around so that the grid lines are now facing the other way, you've transformed the sheet, not rotated it. The same is true for 3D. A 3D object can be rotated (i.e., turned around), but it can also be transformed (i.e., moved around). For example, if you extrude a 2D object (i.e.,...), you're rotating it, but you're also transforming it.
  • #1
DaveC426913
Gold Member
22,443
6,109
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. :wink:

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...
 
Last edited:
Technology news on Phys.org
  • #2
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
  • The cover of the book
  • The top edge of the book
  • The right edge of the book
  • 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, http://www.google.com/search?hl=en&client=safari&q="euler+angles+are+evil"".
  • Eigen rotations.
  • Unit quaternions.
  • Rodrigues parameters.
  • Modified Rodrigues parameters.
  • ...
Please read this wikipedia article on http://en.wikipedia.org/wiki/Rotation_matrix" [Broken], 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.
 
Last edited by a moderator:
  • #3
D H said:
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? :grumpy: 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.
 
Last edited:
  • #4
DaveC426913 said:
Where did I say two parameters? :grumpy: 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.
 
  • #5
D H said:
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.
 
  • #6
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.
 
  • #7
Hm. Well, you lost me right about
D H said:
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. :shy:
 
Last edited:
  • #8
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.
 

Attachments

  • PF20081202_XYZplot.gif
    PF20081202_XYZplot.gif
    5.5 KB · Views: 479

1. How do you calculate the rotational velocity of an object in the x, y, and z axes?

The rotational velocity of an object in the x, y, and z axes can be calculated using the formula ω = Δθ/Δt, where ω is the rotational velocity, Δθ is the change in angle, and Δt is the change in time.

2. What is the difference between rotational and linear motion?

Rotational motion refers to the movement of an object around an axis, while linear motion involves movement in a straight line. In rotational motion, the object maintains a fixed axis of rotation, while in linear motion, the object can move in any direction.

3. How does the moment of inertia affect the rotation of an object in x, y, and z axes?

The moment of inertia is a measure of an object's resistance to rotational motion. The larger the moment of inertia, the more force is needed to rotate the object. Therefore, a larger moment of inertia will result in slower rotation, while a smaller moment of inertia will result in faster rotation.

4. Can an object rotate in multiple axes simultaneously?

Yes, an object can rotate in multiple axes simultaneously. This is known as combined or compound rotation. In this case, the rotational motion of the object can be described as a combination of rotational motions in each axis.

5. How does the direction of rotation in the x, y, and z axes affect an object's movement?

The direction of rotation in the x, y, and z axes will determine the direction of the object's movement. For example, if an object rotates clockwise in the x-axis, it will move in the positive x-direction. Similarly, if it rotates counterclockwise in the y-axis, it will move in the negative y-direction.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • DIY Projects
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
616
  • Precalculus Mathematics Homework Help
Replies
17
Views
905
  • Programming and Computer Science
Replies
4
Views
956
  • Nuclear Engineering
Replies
1
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
Replies
10
Views
1K
Replies
5
Views
1K
Back
Top