Finding an angle with 3 CGPoints

前端 未结 5 1031
长情又很酷
长情又很酷 2021-01-03 14:27

In my application, a user taps 3 times and an angle will be created by the 3 points that were tapped. It draws the angle perfectly. I am trying to calculate the angle at the

5条回答
  •  感情败类
    2021-01-03 14:45

    Using this answer to compute angle of the vector:

    CGFloat angleForVector(CGFloat dx, CGFloat dy) {
        return atan2(dx, -dy) * 180.0/M_PI;
    }
    
    // Compute angle at point Corner, that is between AC and BC:
    
    CGFloat angle = angleForVector(A.x - Corner.x, A.y - Corner.y)
                  - angleForVector(B.x - Corner.x, B.y - Corner.y);
    
    NSLog(@"FULL ANGLE IS: %f, ANGLE IS: %.2f",angle, angle);
    

提交回复
热议问题