# Vector Rotation Problem

###
#1
Members - Reputation: **122**

Posted 03 July 2001 - 08:21 AM

###
#2
Members - Reputation: **2076**

Posted 03 July 2001 - 02:29 PM

dir = [x, y, z]

origin = [0, 0, 0]

newdir = [x'', y'', z'']

**Rotation about the**

*Up*vector:x-0-x'' form the angle you wish to rotate about the

**vector of your object. Obtain this angle by dividing the dot product of the vectors [x] and [x''] by the product of their magnitudes and then taking the inverse cosine (ie, [x]*[x''] = |x||x''|cos(theta), where theta is the angle sought). Then form a rotation matrix using that angle (the value is in radians) and go ahead. The rotation matrix will scale y and z appropriately.**

*Up***Rotation about the**

*Perpendicular*axis:(I''m calling the three axes

**,**

*Up***and**

*Forward***). Assuming the**

*Perpendicular***is analogous to the Z-axis, simply replace [x] and [x''] above with [z] and [z''] and presto!**

*Perpendicular*Both of the transformations describe must preceed the world transformation or be individually multiplied by it.

###
#3
Crossbones+ - Reputation: **7328**

Posted 03 July 2001 - 06:14 PM

Later,

Eck

###
#4
Members - Reputation: **2076**

Posted 03 July 2001 - 06:34 PM

The first is the most important - it won''t give you the desired result. The two vectors lie in different planes - they rotate you in different directions (actually perpendicular planes to each other). Sorry, dude.

The second is that he explicitly wants to do one first, then the other. If, however, he just wanted a straight rotation from vector A to B, he could concatenate a single matrix that had the two angles in different columns.

Hope that helps a bit. Vector math isn''t hard at basic 3D graphics levels - constrained to 3 dimensions. It starts to get complex with

*n*.

###
#5
Members - Reputation: **122**

Posted 04 July 2001 - 08:54 AM

And finally i don''t see, where the UP-Vector comes in.

Maybe it is just the English or my reduced understanding of mathematical expressions.

Thanks in advance

Lars

###
#6
Members - Reputation: **2076**

Posted 04 July 2001 - 09:28 AM

[x] and [x''] are 2D vectors in XZ (singe the angle lies in a natural plane, it is only necessary to consider 2 dimensions), ie (x,z) and (x'',z''). Their dot product would be

[x]*[x''] = (x * x'' + z * z'')

and their magnitudes would be

|x| = sqrt( x * x + z * z)

|x''| = sqrt( x'' * x'' + z'' * z'')

So since [x]*[x''] = |x||x''|cos(theta),

cos(theta) = ([x]*[x''])/(|x||x''|)

=> (x * x'' + z * z'')/(sqrt( x * x + z * z) * sqrt( x'' * x'' + z'' * z'')) = c

theta = acos©

Similar results are obtained for the vertical angle, though I did make a

*huge*mistake. Rotation about the perpendicular axis (Z) is in terms of y, not z, so the vectors should be [y] (=(x,y)) and [y''] (=(x'',y'')).

If this doesn''t clear it up enough, post again! I''ll keep trying until I can explain myself in plain English. Good luck!

###
#7
Members - Reputation: **122**

Posted 04 July 2001 - 09:44 AM

This works for me, (after transforming dir and newdir to coordiante System represented by up, side and cross(up,side))

And i meant, that my english understanding is awful, not your english writing.

Until next time, i have some Realistic maneuvering of Spaceships for the next show, when i finished the issue with the turrets :-)

Lars

###
#8
Members - Reputation: **2076**

Posted 04 July 2001 - 10:07 AM

Looking forward to the Realistic Spaceship motion!

###
#9
Members - Reputation: **122**

Posted 04 July 2001 - 10:20 AM

My main idea for the spaceship movement is, that my AI gives just a command including a movement direction, desired speed and a direction where it want''s to point to.

This command goes to the ship object. The ship object has many engines pointing in different directions, with different thrustpowers. Now i wan''t to compute how much thrust each engine should give to achieve the wished command.

And after that i need to compute the movement result that occurs from enabling the thrusters.

Lars