-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSTPoint.swift
More file actions
31 lines (28 loc) · 958 Bytes
/
STPoint.swift
File metadata and controls
31 lines (28 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// STPoint.swift
// STBaseProject
//
// Created by 寒江孤影 on 2017/10/14.
//
import Foundation
import UIKit
public enum STGeometry {
/// 两点之间的直线距离
public static func distance(between start: CGPoint, and end: CGPoint) -> CGFloat {
hypot(abs(start.x - end.x), abs(start.y - end.y))
}
/// 圆上两点相对于圆心的夹角,返回角度制数值
public static func angle(
onCircleWithRadius radius: CGFloat,
center: CGPoint,
start: CGPoint,
end: CGPoint
) -> CGFloat {
let startVector = CGVector(dx: start.x - center.x, dy: start.y - center.y)
let endVector = CGVector(dx: end.x - center.x, dy: end.y - center.y)
let startAngle = atan2(startVector.dy, startVector.dx)
let endAngle = atan2(endVector.dy, endVector.dx)
let angle = (endAngle - startAngle) * 180 / .pi
return angle >= 0 ? angle : angle + 360
}
}