I am working on a Unity application and am using the Haversine formula to calculate the distance between two points. I know the overall distance + the distance along the latitude and longitude separately given the formula. I know my current position and I know the heading (in degrees) using the compass. However, I am trying to conceptualize how to best get the relative positions of these data points.

Is the point in front of me or behind me as I rotate the camera and change the heading?

Is it to the left of me or right of me? (negative distance in world space)

I was originally planning to plot the points in World space based on their lat and lon. That still may be the best answer. However, the points are all pretty close together (~a few hundred meters) so the precision is pretty tight. I have been thinking of plotting the spaces along a 2-dimensional plane, offsetting them by their position relative to me and the heading location, hence my earlier question.


From your question you know following information:

camera location (i.e. current position); camera heading (i.e. current heading); point locations; distance from camera for all data points.

I suggest also calculating heading from camera position to each data point. See https://www.movable-type.co.uk/scripts/latlong.html

Then derive the difference between your current heading and the bearing to the data points. The value of the difference will inform whether the data point is ahead, behind, to the right or to the left.

calculate bearing diff between two points:

diff = ang2-ang1
if diff > 180.0: 
    diff -=360.0
elif diff<-180.0: 

where ang1 is current/camera heading and ang2 is heading to the data point. Then (pseudocode):

if abs(diff) < 90.0: point is ahead
if abs(diff) > 90.0: point is behind
if diff < 0.0: point is to the left/port
if diff > 0.0: point is to the right/starboard

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.