structHexagon:{ let points: [CLLocationCoordinate2D] let centerLatitude: Double let centerLongitude: Double let startAngle: Double let radius: Double }
let point: MKMapPoint=MKMapPoint(CLLocationCoordinate2D(latitude: centerLatitude, longitude: centerLongitude)) var i =0 var points: [MKMapPoint] = [] var angle = startAngle /180*Double.pi
while i <6 { let x = point.x + radius * sin(angle) *7.612952538285698 let y = point.y - radius * cos(angle) *7.612952538285698 angle +=Double.pi /3 let p: MKMapPoint=MKMapPoint(x: x, y: y) points.append(p) i +=1 }
// 实际距离,单位 m let physicalDistance = points[0].distance(to: points[1]) // CG 距离,两点的距离公式 let cgDistance = sqrt(pow((points[0].x - points[1].x), 2) + pow((points[0].y - points[1].y), 2)) print(cgDistance) print(physicalDistance) print(cgDistance / physicalDistance)
/// Get coordinate moved from current to `distanceMeters` meters with azimuth `azimuth` [0, Double.pi) /// /// - Parameters: /// - distanceMeters: the distance in meters /// - azimuth: the azimuth (bearing) /// - Returns: new coordinate funcshift(byDistancedistanceMeters: Double, azimuth: Double) -> CLLocationCoordinate2D { let bearing = azimuth let origin =self let distRadians = distanceMeters / (6372797.6) // earth radius in meters
let lat1 = origin.latitude *Double.pi /180 let lon1 = origin.longitude *Double.pi /180