Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This function calculates the distance and bearing between two points - SAFE TO USE ON IPHONE
- -- @param:
- -- point1: ZonePoint
- -- point2: ZonePoint
- -- @return
- -- dist: Wherigo.Distance
- -- brg: bearing (degree)
- function VectorToPointSafeToUseOniPhone(point1, point2)
- local EARTH_RAD = 6378137.0
- local lat1 = math.rad( point1.latitude )
- local lat2 = math.rad( point2.latitude )
- local lon1 = math.rad( point1.longitude )
- local lon2 = math.rad( point2.longitude )
- local p1 = math.cos(lat1) * math.cos(lon1) * math.cos(lat2) * math.cos(lon2)
- local p2 = math.cos(lat1) * math.sin(lon1) * math.cos(lat2) * math.sin(lon2)
- local p3 = math.sin(lat1) * math.sin(lat2)
- local distance = math.acos(p1+p2+p3)*EARTH_RAD
- local dist = Wherigo.Distance(distance,'m')
- local dLon = math.rad( point2.longitude-point1.longitude)
- local y = math.sin(dLon) * math.cos(lat2)
- local x = math.cos(lat1)* math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon)
- local brg = math.deg(math.atan2(y, x))
- if brg < 0 then
- brg = brg + 360
- end
- return dist, brg
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement