Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Rotate a 3D vector

by Anonymous Monk
on Oct 18, 2004 at 08:55 UTC ( #400097=note: print w/replies, xml ) Need Help??


in reply to Rotate a 3D vector

RX= 1 0 0
0 cos φ - sin φ
0 sin φ cos φ

RY= cos θ 0 sin θ
0 1 0
0 -sin θ cos θ

RZ= cos ψ -sin ψ 0
sin ψ cos ψ 0
0 0 1
Then your rotation matrix is RX * RY * RZ, with θ the amount of rotation around the X axis, φ the amount of rotation around the Y axis, and ψ the amount of rotation around the Z axis.

Replies are listed 'Best First'.
Re^2: Rotate a 3D vector
by Anonymous Monk on Apr 18, 2010 at 10:29 UTC
    Sorry for bumping an old thread.. i hope this saves a bit of someones time: Ry is wrong, it should be:
    cos(th) 0 sin(th) 0 1 0 -sin(th) 0 cos(th)
    rgds, Mitja
Re^2: Rotate a 3D vector
by Anonymous Monk on Jan 26, 2010 at 19:47 UTC
    how do you find the angles , , and between two vectors?
      To find the angle between the two vectors, you need to normalize them (so they have length of 1 unit) by doing this (v is the vector you want to normalize):
      float distance = sqrt(v.x*v.x + v.y*v.y + v.z*v.z); v.x = v.x/distance; v.y = v.y/distance; v.z = v.z/distance;
      Then find the dot product of the two normalized vectors (Va and Vb):
      float dotProduct = Va.x*Vb.x + Va.y*Vb.y + Va.z*Vb.z;
      This gives you the cosine of the angle, so simple do:
      acos(dotProduct);
      This will give you the angle. I think this post was a bit late :S

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://400097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2020-11-30 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?