SRL Archive - SRL Bugs

AngleBetween


Daniel

2012-03-09 07:06:48

Hi there,

While going through the include, I couldn't help but notice that you passed wrong parametres to the ArcTan method in AngleBetween.

v1.y should be before v1.x!

New:

function AngleBetween(v1, v2: TVector): Extended; overload;
var
a1, a2: Extended;
begin
a1 := ArcTan2(v1.y, v1.x);
a2 := ArcTan2(v2.y, v2.x);

Result := fixRad(a1 - a2)
end;

Easier way to put it:

function AngleBetween(const v1, v2: TVector): Extended; overload;
begin
Result := FixRad(ArcTan2(v1.y, v1.x) - ArcTan2(v2.y, v2.x));
end;

I changed:

a1 := ArcTan2(v1.x, v1.y);
a2 := ArcTan2(v2.x, v2.y);
..to the above.

Regards,
Daniel :)

Gu3st...

2012-03-09 07:19:26

Even easier way to do it:

Result := FixRad(ArcTan2(v2.y - v1.y, v2.x - v1.x));

Coh3n

2012-04-01 23:21:23

Fixed for the next version.