Inner angle between two lines

前端 未结 8 1296
忘掉有多难
忘掉有多难 2020-12-14 20:17

I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2) and P1L1(x1, y1), P2L3(x2, y3)). I want to know t

8条回答
  •  轮回少年
    2020-12-14 20:49

    If you want in between angle in 0 degree to 360 degree then use following code; Its fully tested and functional:

    static inline CGFloat angleBetweenLinesInRadians(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
    double angle1 = atan2(line1Start.y-line1End.y, line1Start.x-line1End.x);
    double angle2 = atan2(line2Start.y-line2End.y, line2Start.x-line2End.x);
    double result = (angle2-angle1) * 180 / 3.14;
    if (result<0) {
        result+=360;
    }
    return result;
    

    }

    Note: Rotation will be clockwise;

提交回复
热议问题