Mar*_*n R 27
给定点p1,p2在具有中心的圆上center,您将首先计算差异向量:
let v1 = CGVector(dx: p1.x - center.x, dy: p1.y - center.y)
let v2 = CGVector(dx: p2.x - center.x, dy: p2.y - center.y)
Run Code Online (Sandbox Code Playgroud)
然后
let angle = atan2(v2.dy, v2.dx) - atan2(v1.dy, v1.dx)
Run Code Online (Sandbox Code Playgroud)
是弧度中这些向量之间的(有向)角度,和
var deg = angle * CGFloat(180.0 / M_PI)
Run Code Online (Sandbox Code Playgroud)
以度为单位的角度.计算出的值可以在-360 .. 360范围内,因此您可能希望将其标准化为0 <= deg <360范围
if deg < 0 { deg += 360.0 }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8056 次 |
| 最近记录: |