PDA

View Full Version : Rotator question


2COOL4-U
18th Nov 2001, 08:13 AM
I have two vectors and I want to get the angle between those two vectors

Anyone got an idea on how to do this?

Mychaeel
18th Nov 2001, 08:58 AM
Given UnrealScript's lack of a decent atan2 function, here's my suggestion:

static final operator(16) float angle (vector v1, vector v2) {

local float DotProduct;

DotProduct = v1 dot v2;

if (DotProduct == 0.0)
return Pi / 2;
else if (DotProduct > 0.0)
return Abs(Atan(VSize(v1 cross v2) / DotProduct));
else
return Abs(Atan(VSize(v1 cross v2) / DotProduct)) + Pi / 2;
}

Use it as MyVector1 angle MyVector2. Returns values between zero and Pi.

2COOL4-U
18th Nov 2001, 10:57 AM
so PI = 360, and 0 = 0 degrees?

Mychaeel
18th Nov 2001, 11:02 AM
No. 0 is 0 (both vectors pointing in the same direction), and Pi is 180 (both vectors pointing in opposite directions). Anything between 180 and 360 doesn't make sense if you're asking for an angle between vectors; 270 in one direction is the same as 90 in the opposite direction, for instance.

Otherwise, have a look at this related thread (http://forums.beyondunreal.com/showthread.php?s=&threadid=92897).