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

# Vector Rotation Problem

Started by Lars W., Jul 03 2001 08:21 AM

8 replies to this topic

Sponsor:

###
#2
Staff Emeritus - Reputation: **1972**

Posted 03 July 2001 - 02:29 PM

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'']

x-0-x'' form the angle you wish to rotate about the

(I''m calling the three axes

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

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: **4575**

Posted 03 July 2001 - 06:14 PM

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

Later,

Eck

###
#4
Staff Emeritus - Reputation: **1972**

Posted 03 July 2001 - 06:34 PM

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

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

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

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
Staff Emeritus - Reputation: **1972**

Posted 04 July 2001 - 09:28 AM

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©

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

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

[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

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

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
Staff Emeritus - Reputation: **1972**

Posted 04 July 2001 - 10:07 AM

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!

Looking forward to the Realistic Spaceship motion!

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

Posted 04 July 2001 - 10:20 AM

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

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