Errors in Spherical to Cartesian mapping - lat/long to position on globe


#1

Hi,
I’m extracting Lat/long co-ordinates from EXIF data in jpg photographs and mapping the locations to a sphere to simulate the globe - I have been through several iterations of code (and useful examples) but have an error that I cant unravel - given the code example i pass lat/long and globe radius and return x,y,z for the relevant point on the globe surface - for certain locations (Hong Kong and Japan) the position is correct but for europe the positions appear 'inverted ’ ie 180 degrees opposite where they should be - eg UK locations are near New Zealand.

here’s the routine - can anyone spot what I’m missing _ (and probably looking straight at ) or suggest alternatives-

ofVec3f ofApp::sphericalToCartesian( float lat, float lon, float radius ){
    ofVec3f result;
    
    lat *= -1;        // inverse latitude.
    lat += 90;        // latitude offset to match geometry of the sphere.
    lon *= -1;        // inverse longitude.
    lon -= 90;        // longitude offset to match geometry of the sphere.
    
    lat *= DEG_TO_RAD;
    lon *= DEG_TO_RAD;
    result.x = radius * sin( lat ) * cos( lon );
    result.y = radius * sin( lat ) * sin( lon );
    result.z = radius * cos( lat );
       
    return result;
}


#2

Hi, one of the included examples is for exactly doing what you need. in examples/3d/quaternionLatLongExample

cheers


#3

thankyou!

with some hacking about that is working nicely !