Frame91
Frame91

Reputation: 3799

How to approximate distance between given points?

I have the values P1,P2,P3,P4 with Screen-Points (x,y) and Longitude,Latitude. In addition to that, I have a camera (with lat,long), the height of the camera (1.6m (constant)) and the orientation of the camera (bearing, pitch, roll). I also have the horizontal view angle and the vertical view angle of the camera :)

Now i want to calculate for PX(lat,long) the estimated position on my display (if its visible). Following Problem

How can I get P(?,?) for given PX(lat,long)? (purple points in the graphic) This seems to be possible because I know the angles of my camera and I have all four vertexes. But I don't know how I can solve this problem.

I need a function, based on this four vertexes, which can translate (lat,long) to (screenX, screenY).

I have a formula, which can translate (screenX, screenY) to (lat,long), but I'm not able to reverse this formula. So, if other points besides the vertexes are required, I can calculate them (but I cannot simply use this formula for every pixel in my screen... that would be a million of method calls every 100 milliseconds...)

Upvotes: 2

Views: 746

Answers (1)

dabhaid
dabhaid

Reputation: 3879

So I may have answered this in a comment on your other thread, but the easiest way to do this is: Ignore the GPS coordinates of your screen edges - in general translate everything to a coordinate space where your camera is the origin, and determine the position of other objects be getting the relative distance between the GPS coordinates using a method that's conditioned well over short distances, like the Haversine formula

Get the relative bearing between your center of projection and the object you wish to display.

You can determine the viewing angle of your axes. You can determine the relative bearing between your virtual object and your center of projection (the direction your camera is pointing) in both axes. You know your screen resolution.

If Alpha is half your angle of view (for a given angle), and Beta is the relative bearing between your center of projection and the object you want to find on screen, then the on screen point is approximately given by

tan(beta) / tan(alpha) * (number of pixels in half a screen in that axis)

Obviously you need to add logic to catch projections outside your screen, whether something is left or right of your center of projection, and if something is behind you (the projection itself doesn't take care of z distance).

Upvotes: 1

Related Questions