http://qs1969.pair.com?node_id=400097

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);