[Question] Get angle XYZ between points
#1

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:x1Float:y1Float:x2Float:y2) {
    return (
180.0 atan2(x1-x2y1-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])));

Reply
#2

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;
}
Reply
#3

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:x1Float:y1Float:x2Float:y2) {
    return (
180.0 atan2(x1-x2y1-y2));

Attached picture with an example

How do I get the angle between the Rocket and the player? To rotate it by vertical?
Reply
#4

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)