PDA

View Full Version : MAXSCRIPT: how to get direction of a vector


Ali
07-13-2002, 02:02 AM
i want to get direction of simple 2d vector lying in XY plane. i used basic math formula. but it failes when 0 devides some thing or when vector is a nagative.

any maxscript func to get vector direction or direction from one point to other.

please reply

Bobo
07-13-2002, 01:13 PM
Originally posted by Ali
i want to get direction of simple 2d vector lying in XY plane. i used basic math formula. but it failes when 0 devides some thing or when vector is a nagative.

any maxscript func to get vector direction or direction from one point to other.

please reply

You could use atan from the two components to calculate the angle. You have to recaulcuate the value based on the signs of the two components - special case for 2nd,3rd and 4th quadrant depending on whether you want 0-360 degrees or 0 to 180 and 0 to -180 output...

For the second case, the script could be something like

fn DirectionOfVector vect =
(
dir = atan (vect.y/vect.x)
if vect.x < 0 and vect.y > 0 then dir = 180+dir
if vect.x < 0 and vect.y < 0 then dir = -180+dir
dir
)

Ali
07-13-2002, 08:37 PM
thanx for hint i was just thinking about some thing like that but its more simple than i thought.

CGTalk Moderation
01-13-2006, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.