Question

i have a list of gps coordinates (long,lat) and i have my current position (long,lat). i found out that by subtracting the two coordinates i find the relative coordinates from my position, and that coordinates i use in my AR app to draw the pois in the opengl world.

the problem is that far-away coordinates will still be too far to "see", so i want an equation to translate everything to be close to my position, but with their original relative position.

double kGpsToOpenglCoorRatio = 1000;
    - (void)convertGlobalCoordinatesToLocalCoordinates:(double)latitude x_p:(double *)x_p longitude:(double)longitude y_p:(double *)y_p {

        *x_p = ((latitude - _userLocation.coordinate.latitude)   * kGpsToOpenglCoorRatio);
        *y_p = ((longitude - _userLocation.coordinate.longitude) * kGpsToOpenglCoorRatio);

    } 

i tried applying Square root in order to give them a "distance limit", but their positions got messed up relatively to their original position.

Was it helpful?

Solution

This might be because GPS uses a spherical(ish) coordinate system, and you're trying to directly map it to a cartesian coordinate system (a plane).

What you could to do is convert your GPS coordinates to a local reference plane, rather than map them directly. If you consider your own location the origin of your coordinate system, you can get the polar coordinates of the points on the ground plane relative to the origin and true north by using great circle distance (r) and bearing (theta) between your location and the remote coordinate, and then covert that to cartesian coordinates using (x,y) = (r*cos(theta), r*sin(theta)).

Better again for your case, once you have the great circle bearing, you can just foreshorten r (the distance). That will drag the points closer to you in both x and y, but they'll still be at the correct relative bearing, you'll just need to indicate this somehow.

Another approach is to scale the size of the objects you're visualizing so that they get larger with distance to compensate for perspective. This way you can just directly use the correct position and orientation.

This page has the bearing/distance algorithms: http://www.movable-type.co.uk/scripts/latlong.html

OTHER TIPS

I ended up solving it using the equation of the gps coordinate intercepted with the circle i want all the pois to appear on, it works perfectly. I didn't use bearings anywhere. here is the code if anyone interested:

- (void)convertGlobalCoordinatesToLocalCoordinates:(double)latitude x_p:(double *)x_p longitude:(double)longitude y_p:(double *)y_p {

    double x = (latitude - _userLocation.coordinate.latitude) * kGpsToOpenglCoorRatio;
    double y = (longitude - _userLocation.coordinate.longitude) * kGpsToOpenglCoorRatio;

    y = (y == 0 ? y = 0.0001 : y);
    x = (x == 0 ? x = 0.0001 : x);

    double slope = x / ABS(y);

    double outY = sqrt( kPoiRadius / (1+pow(slope,2)) );
    double outX = slope * outY;

    if (y < 0) {
        outY = -1 * outY;
    }

    *x_p = outX;
    *y_p = outY;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top