Skip to main content
gamedev.net
🔒 Locked

Vector rotation question

Started by lwinkenb May 2, 2004 at 6:30 PM 2 replies 300+ views
Original Post
lwinkenb
lwinkenb
If an object is rotated d1 degrees about the vector v1 [x1,y1,z1], and then rotated d2 degrees about the vector v2 [x2,y2,z2], what is the final degrees rotated about what vector? I''m not sure how to solve this one =/
shadow12345
shadow12345
I *think* but am not totally sure that it would be:

RotationVector = (v1 + v2) / sqrt(v1^2+v2^2)
Angle = (d1 + d2)

I just added the vectors together to get the resultant, then normalized it because that''s what you should always do, and just added the angles together. I''m pretty sure this is right.
Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...
Fruny
Fruny
Shadow12345 - It's not.

Counter example:
v1 = [1, 0, 0] d1 = 90°
v2 = [0, 1, 0] d2 = 90°
Result:
v = [sqrt(2)/2, sqrt(2)/2, 0]
d = 90°

lwinkenb - That's exactly the problem quaternions solve.


Assume |v1| = |v2| = 1

Let A = [cos(d1/2), v1x.sin(d1/2), v1y.sin(d1/2), v1z.sin(d1/2)] = [Aw,Ax,Ay,Az]
Let B = [cos(d2/2), v2x.sin(d2/2), v2y.sin(d2/2), v2z.sin(d2/2)] = [Bw,Bx,By,Bz]

Q'= A*B = [Qw,Qx,Qy,Qz]
= [ Aw.Bw - Ax.Bx - Ay.By - Az.Bz,
Aw.Bx + Ax.Bw + Ay.Bz - Az.By,
Aw.By - Ax.Bz + Ay.Bw + Az.Bx,
Aw.Bz + Ax.By - Ay.Bx + Az.Bw ]

cos(d'/2) = Aw.Bw - Ax.Bx - Ay.By - Az.Bz
v'x.sin(d'/2) = Aw.Bx + Ax.Bw + Ay.Bz - Az.By
v'y.sin(d'/2) = Aw.By - Ax.Bz + Ay.Bw + Az.Bx
v'z.sin(d'/2) = Aw.Bz + Ax.By - Ay.Bx + Az.Bw

|(Qx,Qy,Qz)| = |sin(d'/2)|
= sqrt(1-cos(d'/2)^2)
= sqrt(1-Qw)

v' = (Qx,Qy,Qz) / sqrt(1-Qw)
d' = acos(Qw)*2




[edited by - Fruny on May 3, 2004 12:51:08 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
shadow12345
shadow12345
does it work unless you rotate one axis onto another though?
Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.