20.02.2009, 21:54
Well, it's working perfect for me, so i think you use it wrong.
Test cases:
Edit: fix for negative angles (gta fix negative angles for us, but for displaying in messages or whatever, its better to fix them here)
Test cases:
pawn Код:
new Float:coords[][] =
{
{ 0.0, 0.0},
{ 0.0, 1.0},
{ 0.0, -1.0},
{ 1.0, 0.0},
{ 1.0, 1.0},
{ 1.0, -1.0},
{-1.0, 0.0},
{-1.0, 1.0},
{-1.0, -1.0}
};
for (new i = 0; i < sizeof coords; i++)
for (new j = 0; j < sizeof coords; j++)
if (i != j)
printf("Angle between {%2.1f, %2.1f} and {%2.1f, %2.1f} : %4.2f", coords[i][0], coords[i][1], coords[j][0], coords[j][1], Angle2D(coords[i], coords[j]));
Edit: fix for negative angles (gta fix negative angles for us, but for displaying in messages or whatever, its better to fix them here)
pawn Код:
Float:Angle2D(Float:PointA[], Float:PointB[])
{
new
Float:Dist[2],
Float:Angle
;
Dist[0] = PointA[0] < PointB[0] ? PointB[0] - PointA[0] : PointA[0] - PointB[0];
Dist[1] = PointA[1] < PointB[1] ? PointB[1] - PointA[1] : PointA[1] - PointB[1];
Angle = atan2(Dist[1], Dist[0]);
Angle = PointA[0] < PointB[0] ? 270.0 + Angle : 90.0 - Angle;
Angle = PointA[1] < PointB[1] ? Angle : 180.0 - Angle;
return Angle < 0.0 ? Angle + 360.0 : Angle;
}