Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------------------------------
- -- this function rotates a given array of Points using an origin
- -- @param:
- -- zPoints: Points (array of ZonePoints)
- -- origin: Point
- -- alpha: float (degree: 0° - 359°)
- -- @return
- -- zPoints: Points (array of ZonePoints)
- function rotateZone(zPoints, origin, alpha)
- local index
- local value
- local newBearing = 0
- local bearing
- local distance
- alpha = math.fmod(math.floor(alpha), 360)
- if alpha == 0 then
- return zPoints
- end
- for index, value in pairs(zPoints) do
- -- Calculate distance and bearing between origin and point of zone
- distance, bearing = VectorToPointSafeToUseOniPhone(origin, zPoints[index])
- -- calculate new bearing
- if bearing + alpha >= 360 then
- newBearing = bearing + alpha - 360
- elseif bearing + alpha < 0 then
- newBearing = bearing + alpha + 360
- else
- newBearing = bearing + alpha
- end
- --set new lat and long value
- zPoints[index] = Wherigo.TranslatePoint(origin, distance, newBearing)
- end
- return zPoints
- end
- ---------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement