Angle between two lines is wrong

后端 未结 3 1003
执笔经年
执笔经年 2021-02-06 07:11

I want to get angles between two line. So I used this code.


int posX = (ScreenWidth) >> 1;

int posY = (ScreenHeight) >> 1;

double radians, de         


        
3条回答
  •  悲&欢浪女
    2021-02-06 08:08

    If you have 3 points and want to calculate an angle between them here is a quick and correct way of calculating the right angle value:

    double AngleBetweenThreePoints(CGPoint pointA, CGPoint pointB, CGPoint pointC)
    {
        CGFloat a = pointB.x - pointA.x;
        CGFloat b = pointB.y - pointA.y;
        CGFloat c = pointB.x - pointC.x;
        CGFloat d = pointB.y - pointC.y;
    
        CGFloat atanA = atan2(a, b);
        CGFloat atanB = atan2(c, d);
    
        return atanB - atanA;
    } 
    

    This will work for you if you specify point on one of the lines, intersection point and point on the other line.

提交回复
热议问题