I have a math problem can anyone help me?
#1

hi, i have some math problems, and i can't get out of it
the thing is: i want to make a object pointing into the direction
of some coordinates (xyz), but i can't get out of it...

see like if i be like at a point A (we just call it point a) and i have coordinates of point B
then a want an object That stands on Point A to point at point B

doe anyone have a idea to fix this?
Reply
#2

Get the angle (bearing) from Point A to Point B, then point (rotate) the object to that bearing.

Check the Useful Functions topic for Get2DAngle() or GetAngle2D(), one of the two.

~Cueball~
Reply
#3

Quote:
Originally Posted by Cuecumber
Get the angle (bearing) from Point A to Point B, then point (rotate) the object to that bearing.

Check the Useful Functions topic for Get2DAngle() or GetAngle2D(), one of the two.

~Cueball~
thats for the quick post man!
i rly appreciate it i will try it out right now

EDIT: Fuck!, i cant find it anywhere
Reply
#4

My mistake, it was Angle2D()
pawn Код:
Float:Angle2D(Float:PointA[], Float:PointB[]) // Credits to 0rb - http://forum.sa-mp.com/index.php?topic=6...#msg582490]http://forum.sa-mp.com/index.php?topic=61574.msg582490#msg582490
{
  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;
}
That should do the job perfectly

EDIT: Ergh, it appears to have added in the url tags for me, when I didn't want it to, perhaps that's a new function of the forum formatting.

~Cueball~
Reply
#5

Quote:
Originally Posted by Cuecumber
My mistake, it was Angle2D()
pawn Код:
Float:Angle2D(Float:PointA[], Float:PointB[]) // Credits to 0rb - http://forum.sa-mp.com/index.php?topic=6...#msg582490]http://forum.sa-mp.com/index.php?topic=61574.msg582490#msg582490
{
  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;
}
That should do the job perfectly

EDIT: Ergh, it appears to have added in the url tags for me, when I didn't want it to, perhaps that's a new function of the forum formatting.

~Cueball~
well...
now i am busy with it but i am stuck with a problem...
in Angle2D() are 2 parameters 1 is point A and 2 is Point B but i am using coordinates so i need one with XYZ
Reply
#6

You need to pass arrays to the function, which contain your co-ordinates (your "XYZ" (though with this function, there is no Z-axis evaluation)):
pawn Код:
new Float:PointA[2] =
{
  // X, Y of Point A. For Example:
  123.45, 678.90
},
  Float:PointB[2] =
{
  // X, Y of Point B. For Example:
  987.65, 432.10
};

new Float:angle = Angle2D(PointA, PointB);
OR

pawn Код:
new Float:angle = Angle2D({ 123.45, 678.90 }, { 987.65, 432.10 }); // PointA, PointB.
Just use that kind of syntax, and you're in business

~Cueball~
Reply
#7

In fact, it's just easier (and much faster) to do this:

pawn Код:
Float:Angle2D(Float:x1, Float:y1, Float:x2, Float:y2)
{
  x2 -= x1;
  y2 -= y1;
  return atan3(y2, x2);
}
atan3 is a fix for atan2, which don't work correctly for sa:mp.

pawn Код:
Float:atan3(Float:y, Float:x)
{
  x = atan2(y, x) - 90;
  return x < 0.0 ? x + 360 : x;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)