Archived

This topic is now archived and is closed to further replies.

Vector Rotation Problem

This topic is 6040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi The Situation is the following: I have an Object which points into an Direction (dir). Now i want that this Object points into another Direction (newdir). But the Object can only be rotated around two axes, the upvector (up) and the sideVector (side) The Problem is, that i need the arcs for each of the two rotations (upRot),(sideRot) to make some movement restrictions. I can get one of the angles, without any Problems, but i can''t get the second one. (But maybe it is stupid simple and there is something sitting in my head eating all my knowledge) Lars

Share this post


Link to post
Share on other sites
If I understand you correctly, you wish to translate from your original vector (dir) to an arbitrary new direction (newdir) using only vertical and horizontal rotation (like a tank turret that can swivel side-to-side and raise/lower its aim). Okay:

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 Up 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.

Rotation about the Perpendicular axis:
(I''m calling the three axes Up , Forward and Perpendicular ). Assuming the Perpendicular is analogous to the Z-axis, simply replace [x] and [x''] above with [z] and [z''] and presto!

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

Share this post


Link to post
Share on other sites
First of all let me say that vector math has always given me problems. That said I just want to know if this will work, not if it''s efficient. Could you calculate the angles of both vectors then just rotate the first vector by the difference of the two vectors? It seems logical to me, but like I said vector math is tough for me.


Later,
Eck

Share this post


Link to post
Share on other sites
No, you don''t want to do that for two reasons:

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 .

Share this post


Link to post
Share on other sites
I have Problems understanding your Syntax, what does x-0-x'' mean, and what is the Vector you referring as [x] and [x''].
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

Share this post


Link to post
Share on other sites
Sorry about that. x-0-x'' would be the angle formed by the points x (from the original vector), 0 (from the origin) and x'' (from the destination vector), lying in the XZ plane (where X is left-to-right, Y is bottom-to-top [UP] and Z is out-to-in - in other words, a left-handed coordinate system).

[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(c)

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!

Share this post


Link to post
Share on other sites
Thanks alot Oluseyi

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

Share this post


Link to post
Share on other sites
Keep the questions coming! It gives me something to do and an opportunity to think and problem solve (I''m not working as a programmer right now, so I''m bored stiff!) Physics, pseudo-AI and interaction are my favorite parts of game programming, because they determine the quality of gameplay, to my mind.

Looking forward to the Realistic Spaceship motion!

Share this post


Link to post
Share on other sites
Ok then,i can describe my idea, but i will post a new thread when i have a detailed question, first i try to solve it my self.

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

Share this post


Link to post
Share on other sites