[Question] Get angle XYZ between points - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Question] Get angle XYZ between points (
/showthread.php?tid=574338)
[Question] Get angle XYZ between points -
Logofero - 16.05.2015
Question: Get angle XYZ between points
Given: There are 2 points:
Код:
Float:p1[3]; //player
Float:p2[3]; //arrow
My working example for calculating the angleZ (horizontal):
PHP код:
stock Float:GetAngleZFromPoints(Float:x1, Float:y1, Float:x2, Float:y2) {
return (180.0 - atan2(x1-x2, y1-y2));
}
Q: How to get a calculation for vertical angle?
Method found. Thanks
iggy1 http://forum.sa-mp.com/showthread.ph...67#post2625467
Get angleY (vertical) between points:
PHP код:
stock Float:GetAngleYFromPoints(Float:p1[3], Float:p2[3]) {
p1[0] -= p2[0]; //x
p1[1] -= p2[1]; //y
return (360.0 - atan((p1[2]-p2[2])/floatsqroot(p1[0]*p1[0]+p1[1]*p1[1])));
}
Re: [Question] Get angle XYZ between points -
iggy1 - 16.05.2015
The link in my sig has working example (arrow.inc)
Taken from the include with name changed, returns xy angle between 2 points:
X and Y being the point from which you want the angle.
pawn Код:
stock Float:AngleBetweenPoints(Float:X, Float:Y, Float:PointX, Float:PointY)
{
new Float:fAngle;
if(X > PointX && Y > PointY)
fAngle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
if(X > PointX && Y <= PointY)
fAngle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
if(X <= PointX && Y > PointY)
fAngle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
if(X <= PointX && Y <= PointY)
fAngle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
return fAngle >= 360.0 ? floatsub(fAngle, 360.0) : fAngle;
}
Re: [Question] Get angle XYZ between points -
Logofero - 16.05.2015
Quote:
Originally Posted by iggy1
The link in my sig has working example (arrow.inc)
Taken from the include with name changed, returns xy angle between 2 points:
pawn Код:
stock Float:AngleBetweenPoints(Float:X, Float:Y, Float:PointX, Float:PointY) { new Float:fAngle; if(X > PointX && Y > PointY) fAngle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y))); if(X > PointX && Y <= PointY) fAngle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0); if(X <= PointX && Y > PointY) fAngle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0); if(X <= PointX && Y <= PointY) fAngle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0); return fAngle >= 360.0 ? floatsub(fAngle, 360.0) : fAngle; }
|
Thanks for answer. But you represent the function that I know:
PHP код:
stock Float:GetAngleZFromPoints(Float:x1, Float:y1, Float:x2, Float:y2) {
return (180.0 - atan2(x1-x2, y1-y2));
}
Attached picture with an example
How do I get the angle between the Rocket and the player? To rotate it by vertical?
Re: [Question] Get angle XYZ between points -
Logofero - 16.05.2015
Quote:
Originally Posted by iggy1
The link in my sig has working example (arrow.inc)
|
Thank you very much what you have written to me.
I found the right formula for your
arrow.inc. The result was he was looking for. Method found.
Decided:
PHP код:
stock Float:GetAngleYFromPoints(Float:p1[3], Float:p2[3]) {
p1[0] -= p2[0]; //x
p1[1] -= p2[1]; //y
return (360.0 - atan((p1[2]-p2[2])/floatsqroot(p1[0]*p1[0]+p1[1]*p1[1])));
}
Thanks!