[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

3D rotation of a vertex about the origin

Posted on 2006-04-06
8
Medium Priority
?
1,331 Views
Last Modified: 2008-02-01
I don't want anything overly complicated nor a 500 page web site to read.  

I want a mathmatical equation(s) to rotate a given vertex at (x,y,z) with a current angle Theta to the X axis, Phi to the Y axis, and Omega to the Z axis.  The defined rotation is about all three axis defined by a rotation of Theta + Theta' about the X axis, Phi + Phi' to the Y axis, and Omega + Omega' to the Z axis.  Where Theta', Phi' and Omega' are the user defined rotation to rotate beyond the current rotation about each axis.

The equation should work with no exceptions such as 90 degree rotation about the Z axis.  I've been looking at this complex matrix rotation stuff for a while now and honestly do not feel like figuring out the derrived rotation matrix for a rotation on all three axis.  Answer should be in the form:

x = something
y = something
z = something

Another question that is not required to be answered is given an arbitrary vector to rotate about how to calculate rotation about that axis.  So say given vector (v.x, v.y. v.z) and a rotation about that vector with a measure of the current angle of the point given by the dot product of the y axis and the line (giving a perpendicular line to the Y axis and the given vector) how could I rotate a point in 3D space about that arbitrary line.

Thank you!

~Aqua
0
Comment
Question by:Andrew Beers
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 16395337
To rotate a point by an angle omega around the Z axis, do this:

x' = x*cos(omega) - y*sin(omega)
y' = x*sin(omega) + y*cos(omega)
z' = z

Similarly, around the x-axis:
x' = x
y' = y*cos(theta) - z*sin(theta)
z' = y*sin(theta) + z*cos(theta)

Around the y-axis:
x' = z*sin(phi) + x*cos(phi)
y' = y
z' = z*cos(phi) - x*sin(phi)

To perform a sequence of rotations around these axes, just do those transformations in sequence.

0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 16395405
You don't need to worry about 'the measure of the current angle'.  These transforms work just fine without that.

Your second question about rotating around a line in space becomes very easy once you learn about matrix transforms, but it appears you don't want to do that.
0
 
LVL 10

Author Comment

by:Andrew Beers
ID: 16395427
It isn't that I don't want to learn about matrix transforms but I'm not on the top of my game when it comes to multiplying complex matricies with a vector matrix....  If you can explain how to do the matrix and multiply it out.. heh...  That's just what I don't understand... Matrix mathematics has now been over 4 years ago... and I haven't kept up on that knowledge so it's all but gone.  

It's not that I don't want to learn how it's just reading it from crappy explinations in a book that don't step through it lose me and then I get adjitated...  

:-)

If your up for a lil' teaching lesson on matrix multiplication of a 4x4 * a 1x4 matrix I'm all ears.

~Aqua
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Andrew Beers
ID: 16395450
BTW:  Thank you for the solution... an accept is yours.  :-)

~Aqua
0
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 2000 total points
ID: 16395575
The omega rotation above:

x' = x*cos(omega) - y*sin(omega)
y' = x*sin(omega) + y*cos(omega)
z' = z

corresponds to this matrix-vector multiplication:
[x']     [ cos(omega)    -sin(omega)     0   ] [ x ]
[y'] =  [ sin(omega)     cos(omega)     0   ] [ y ]
[z'] =  [      0                    0               1   ] [ z ]

But doing the transforms involves more than matrix-vector multiplication.  You have to do matrix-matrix multiplication to string several transforms together, and you also have to do a matrix inversion to reverse a transform.

To rotate points around an arbitrary line L0, using quaternions, this is the general process:
1.  Find a translation matrix T that moves L0 so that it crosses the origin.  Let L1 be the transformed line from this.
2.  Find a rotation matrix R1 that rotates L1 around the Z-axis so that the transformed line L2 rests in the X-Z plane.  
3.  Find another rotation matrix R2 that rotates around the Y-axis so that L2 comes to be aligned with the Z-axis.  
Now the transform matrix (R2 * R1 * T) takes  points along the original L0 line and aligns them with the Z-axis.
4.  Create a rotation matrix R3 that rotates everything around the Z-axis by your desired rotation angle.
Let X = (R2 * R1 * T)
Let X' = the matrix inverse of X
Let Q = (X' * R3 * X)
The matrix Q will perform the transform you want.  X pulls everything in to surround the Z-axis, R3 rotates everything around the Z axis, then X' moves everything back.
0
 
LVL 10

Author Comment

by:Andrew Beers
ID: 16395605
Question on rotation:

Given point 0,1,0 rotated about the Z axis by (PI / 2) radians or 90 degrees:

I get:
Rotated by 90 degrees about the Z axis (-1 , 6.123031769111886e-17 , 0) W:1

When it should be -1,0,0 correct?

Do I need to check the values of Zero going into this?

If you are familiar with javascript here's the code.. :-P  ...Seems you've dabbled a lot in different TA's so...

function rotateZ(theta){
      //Rotate around the z-axis:
      var       x = this.x,
            y = this.y;
      this.x = x * Math.cos(theta) - y * Math.sin(theta);
      this.y = x * Math.sin(theta) + y * Math.cos(theta);
}

Passed either parameter PI / 2 or 90 the above print out is with PI / 2 with 90 as a parameter I get:

Rotated by 90 degrees about the Z axis (-0.8939966636005578 , -0.4480736161291701 , 0) W:1

So I make the blind assumption that JavaScript deals with trig functions in Radians, but this has yet to explain the correct X value for 0,1,0 rotated 90 degrees about the Z axis and an incorrect Y value.

If this is just an incorrect rounding error on JavaScripts part with the ^e-17 I can truncate after so many decimal places but...  I want to make sure first.

Thank you!

~Aqua
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 16395678
6.123031769111886e-17 is ridiculously close to zero, don't worry about it.

Almost all programming languages' trigonometric library functions work with radians, and I believe javascript is no exception.

Also, when it comes to doing exact comparisons of floating point numbers, you shouldn't.  Instead of checking if (x == y), you should be checking something more like if (Math.fabs(x - y) < epsilon) where epsilon is a really small number that meets the needs of your application.
0
 
LVL 10

Author Comment

by:Andrew Beers
ID: 16397813
Thank you Nova.. You've been a great help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question