HELP! calculating vector components [RESOLVED]
hi... i know this has been asked before but i haev spent the last half an hour searchin the forums for the answer.. basically does anyone have some code which you can use to turn two points (x1,y1),(x2,y2) into a vector, basically i want to find the direction from object 1 to object 2 in a vector form (assume the magnitude=1) and i know you need a different equation depending on which quadrant its in (0-90,90-180 etc) but i cant figure it out any help would b much appreciated
1 Attachment(s)
Re: HELP! calculating vector components
Hope this is what you want.
http://www.vbforums.com/attachment.p...postid=1837024
Vector from A to B
= ( 9 - (-12) , 20 - (-10) )
In other words...
(Destination.X - Start.X, Destination.Y - Start.Y)
This example would give you (21, 30).
To get your unit vector, divide both x and y by the magnitude...
Mag = Sqrt(21^2 + 30^2)
x = 21/mag
y = 30/mag
Giving you a unit vector of (0.57346, 0.81923), new magnitude = 1.
(It doesn't matter what quadrants the points are in :))
Gurus: If I have got this wrong, please let me know because i'm not a math god :D