How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

classic Classic list List threaded Threaded
6 messages Options
Mirro187 Mirro187
Reply | Threaded
Open this post in threaded view
|

How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

osg3.6.4&osgearth2.10.0
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

Convert each point to world coordinates (ECEF geocentric) and then subtract one from the other.
GeoPoint::toWorld() will convert from lat/long to world.
Glenn Waldron / Pelican Mapping
Mirro187 Mirro187
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

Thank you for your question and answer.How do you write the ECEF geocentric code?What's wrong with the code below?

osg::Vec3d worldPos;
osg::ref_ptr<osgEarth::MapNode> mapNode = pSceneView->getMapNode();
if (mapNode.valid())
{
        const osgEarth::SpatialReference* latLong = mapNode->getMap()->getSRS()->getGeocentricSRS();
        latLong->transformToWorld(osg::Vec3d(pos.x(), pos.y(),pos.z()), worldPos);
}
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

If you want a Lat/Long SRS, use getGeographicSRS() instead of getGeocentricSRS().
You did not say what "pos" is so I will assume that "pos" is (long, lat, z) with long and lat in degrees.
Glenn Waldron / Pelican Mapping
Mirro187 Mirro187
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

You said Convert each point to world coordinates (ECEF geocentric) and then subtract one from the other.
GeoPoint::toWorld() will convert from lat/long to world.

Is the code I write the way you say?

osg::Vec3d worldPos;
osg::ref_ptr<osgEarth::MapNode> mapNode = pSceneView->getMapNode();
if (mapNode.valid())
{
                        //pos is lat/long coordinate
                        const osgEarth::SpatialReference* pGeographic = mapNode->getMap()->getSRS()->getGeographicSRS();
                        GeoPoint geoPos(pGeographic, pos.x(), pos.y(), pos.z());
                        //Convert ECEF geocentric
                        const osgEarth::SpatialReference* pGeocentric = mapNode->getMap()->getSRS()->getGeocentricSRS();
                        GeoPoint geoECEF;
                        geoPos.transform(pGeocentric, geoECEF);
                        geoECEF.toWorld(worldPos);
}
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the offset vector of two longitude and latitude coordinates in osgearth?

Assuming you have a round earth map, all you need is

const osgEarth::SpatialReference* pGeographic = mapNode->getMap()->getSRS()->getGeographicSRS();
GeoPoint geoPos(pGeographic, pos.x(), pos.y(), pos.z());
geoPos.toWorld(world);

If you have a projected map, your code is fine, although you do not need the final toWorld call since the ECEF coordinate is already in geoECEF.
Glenn Waldron / Pelican Mapping