# Finding the 3D points of Latitude Longitude

edited May 2010 in SDK
We are working on a 3D project in openGL that maps the objects to different parts of the world using their latitudes and longitudes positions. But the problem is that the world is not perfect sphere and using a constant for that mapping is not possible for correct positioning of objects. So we decided to use the global mapper for that purpose. So my question is that does global mapper provides us with such functionality to find the correct 3D coordinates of the objects using their latitudes and longitudes given the reference is always at 0:0:0 lat and 0:0:0 long of earth.

Eagerly waiting for your early response.

With Best Regards,
Atif

• edited May 2010
Atif,

It sounds like what you might be after are ECEF (earth-centered earth-fixed) coordinates for a lat/lon location. Currently you can get ECEF coordinates out when exporting to a DXF format file. There is not currently any other way to convert your lat/lon values to a ECEF value based on the current ellipsoid.

Since you sound like developers, I can provide you our source code that converts a lat/lon value to ECEF coordinates based on an ellipsoid. The formulas are very simple.

//*********************************************************************
//
// METHOD NAME:
// DatumConvertor::convertToECEF
//
// DESCRIPTION:
// Converts the given latitude/longitude value (in radians)
// into ECEF (Earth Centered Earth Fixed) coordinates.
//
//********************************************************************/
bool
DatumConvertor::convertToECEF
(
double& aX,
double& aY,
double& aZ,
)
{
// Get the datum parameters
DatumParameters* theDatumParams = getDatumParameters( aDatum );
if ( NULL == theDatumParams )
{
return ( false );
}

// Get the ellipsoid parameters
EllipsoidParameters* theEllipsoidParams =
getEllipsoidParameters( theDatumParams->mEllipsoid );
if ( NULL == theEllipsoidParams )
{
return ( false );
}

// Calculate the sine and cosine of the lat/lon values
double theCosLat = ::cos( aY );
double theCosLon = ::cos( aX );
double theSinLat = ::sin( aY );
double theSinLon = ::sin( aX );

// Calculate the Prime Vertical of Curvature (meters)
double theTemp = 1.0 - theEllipsoidParams->mEccSquared * theSinLat * theSinLat;
if ( theTemp <= 0.0 )
{
return ( false );
}
double thePVC = theEllipsoidParams->mMajorAxis / ::sqrt( theTemp );

// Calculate the ECEF x, y, and z values
aX = ( thePVC + aZ ) * theCosLat * theCosLon;
aY = ( thePVC + aZ ) * theCosLat * theSinLon;
aZ = ( thePVC * ( 1.0 - theEllipsoidParams->mEccSquared ) + aZ ) * theSinLat;

return ( true );
} // end of function DatumConvertor::convertToECEF

Let me know if I can be of further assistance.

Thanks,

Mike
Global Mapper Support
support@globalmapper.com
• edited May 2010
Hi Mike,

Thanks for your reply. I understand what you said but where do I find the DatumParameter and EllipsoidParameter classes, for which you have created instances in the source code that you provided.

With Best Regards,
Atif
• edited May 2010
Atif,

Really all you need is the ellipsoid one, here is its declaration:

// Ellipsoid info type
struct EllipsoidParameters
{
double mMajorAxis; // Major axis in meters
double mMinorAxis; // Minor axis in meters
double mDeltaA; // Equatorial radius shift from WGS84
double mDeltaF; // Flattening shift from WGS84
double mFlattening; // Ellipsoid flattening
double mEccSquared; // Eccentricity squared
double mEcc2Squared; // Secondary eccentricity squared
};

You would just use the semi-major axis of your ellipsoid and the eccentricity squared value for the ellipsoid in the formula. You would likely use the WGS84 values in your application unless you needed another ellipsoid for some reason.

Thanks,

Mike
Global Mapper Support
support@globalmapper.com