Rotation between two points
#1

Hi guys,

I have two 3D points (X, Y, Z) and wondered how I would get X, Y, Z rotation angles between these points.
I've searched these forums, the interwebs, and asked for help, yet nobody seems to know how to do something like this.

To be more specific, I'm trying to create an object at point 1 which will face point 2, so I need the rotation values which will make it face point 2.
I'm assuming it'd use some complex (or not) math functions, but all of my attempts with just about every function failed. :<

Hopefully there are some math geeks out there who can help.
Reply
#2

I've figured it out for 2D coordinates (X,Y) but not yet for 3D coordinates (X,Y,Z)

pawn Код:
Float:GetAngleBetweenPoints(Float:X1,Float:Y1,Float:X2,Float:Y2)
{
  new Float:angle=atan2(X2-X1,Y2-Y1);
  if(angle>360)angle-=360;
  if(angle<0)angle+=360;
  return angle;
}
I once used it to make an in-game compass that pointed out nearby players and the user's objective.


looked like this (if player was looking straight North)
|||||||||N|||||||||
|=player
|=objective
Reply
#3

Quote:
Originally Posted by Joe Staff
I've figured it out for 2D coordinates (X,Y) but not yet for 3D coordinates (X,Y,Z)

pawn Код:
Float:GetAngleBetweenPoints(Float:X1,Float:Y1,Float:X2,Float:Y2)
{
  new Float:angle=atan2(X2-X1,Y2-Y1);
  if(angle>360)angle-=360;
  if(angle<0)angle+=360;
  return angle;
}
Thanks for trying, but I think I had already stumbled across something similar in my attempts to find what I wanted.
The problem is, not only is it for two 2D points, it also only returns one angle, I'd need three.
Reply
#4

I spent a WHOLE lotta time trying to figure that out.

The only results I could find were some formulas that require a DOT algorithm, which isn't possible (as far as I know) in the pawn version for SA-MP.
Reply
#5

Quote:
Originally Posted by Joe Staff
I spent a WHOLE lotta time trying to figure that out.

The only results I could find were some formulas that require a DOT algorithm, which isn't possible (as far as I know) in the pawn version for SA-MP.
Sigh.. well thanks anyway.
Hopefully somebody knows a way of doing this in pawn.
Reply
#6

Bump. :\
Reply
#7

Quote:
Originally Posted by ev0lutionnn
Bump. :\
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)