osgEarth::Annotation::RectangleNode distance not correct

classic Classic list List threaded Threaded
3 messages Options
roni roni
Reply | Threaded
Open this post in threaded view
|

osgEarth::Annotation::RectangleNode distance not correct


  Hi All,

  While I was working in my osgearth project I notice that the given distance to build a RectangleNode was not matching the map. To do a test  I have changed the osgearth_annotation.cpp and replaced the rectangle around San Diego to do be in the center of London and the left side center of the rectangle to be on top of Cardiff. The distance between this too points is 211.91 KM so I multiplied by 2 to get the dimensions of my rectangle 423.82. I actually for testing build a square.

      then I ran osgearth_annotationd openstreetmap_flat.earth. If I leave the units as Units::KILOMETERS it does not work]
but if I change to Units::MILES it matches exactly on top of Cardiff. Am I doing something wrong?

       {
        // A rectangle around San Diego
        Style rectStyle;
        rectStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::Green, 0.5);
        rectStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
        rectStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;
//        RectangleNode* rect = new RectangleNode(
//            mapNode,
//            GeoPoint(geoSRS, -117.172, 32.721),
//            Distance(300, Units::KILOMETERS ),
//            Distance(600, Units::KILOMETERS ),
//            rectStyle);
//        annoGroup->addChild( rect );
        RectangleNode* rect = new RectangleNode(
                    mapNode,
                    GeoPoint(geoSRS, -0.118092, 51.5099),
                    Distance(423.82, Units::KILOMETERS ),
                    Distance(423.82, Units::KILOMETERS ),
                    rectStyle);
        annoGroup->addChild( rect );

        editGroup->addChild( new RectangleNodeEditor(rect) );
    }

    Cheers,

    Roni
roni roni
Reply | Threaded
Open this post in threaded view
|

Re: osgEarth::Annotation::RectangleNode distance not correct

 Hi All,

  One more finding in this issue:

  if I use GeoMath to calculate the distance between the two points it gives me the correct value if I do this:

      double dist_earth = osgEarth::GeoMath::distance(osg::DegreesToRadians(51.5099),
                                                    osg::DegreesToRadians(-0.118092),
                                                    osg::DegreesToRadians(51.4816),
                                                    osg::DegreesToRadians(-3.17909));

     dist_earth = 212149 meters

     However it seems the code to draw the retangle uses lon and lat instead of lat and lon which returns me a wrong distance between the  points

    double dist_earth2 = osgEarth::GeoMath::distance(osg::DegreesToRadians(-0.118092),
                                                    osg::DegreesToRadians(51.5099),
                                                    osg::DegreesToRadians(-3.17909),
                                                    osg::DegreesToRadians(51.4816));

    dist_earth = 340763 meters

    Roni
roni roni
Reply | Threaded
Open this post in threaded view
|

Re: osgEarth::Annotation::RectangleNode distance not correct

In reply to this post by roni

   Hi All,

   If you need precision in your RectangleNode or CircleNode there is a work around for the problem I have encounter using these specific classes. Instead you can create your own osgEarth::Symbology::Geometry class and push_back the latitude and longitude you need based on the distance from a initial latitude and longitude and create a osgEarth::Features::Feature.
   Below is the example to show that it will work very precisely:

   The distance from London to Paris is about 344Km. So if you create a circle on top of London with the this range it should hit Paris.

         osgEarth::Symbology::Geometry geometry =  new osgEarth::Symbology::Polygon();

        double lat_orig = 51.5099 // London latitude
        double lon_orig = -0.118092 // London longitude
        double lat, lon;
        double dist = 344;
        double brg = 0;

        osgEarth::Distance radius = osgEarth::Distance(dist, unit).as(osgEarth::Units::METERS);

        unsigned n_points = 64;
        double angle = brg;
        double step =  360.0 / n_points;

        for( unsigned j = 0; j < n_points+1; ++j, angle += step )
        {
            latLonFromDistance(lat_orig _lon_orig, radius.getValue(), angle, lat, lon );
            geometry->push_back(lon, lat);
        }

   I have create this function:

void
latLonFromDistance( double lat_orig, double lon_orig, double dist, double angle, double& lat2, double& lon2 )
{
    double brng = osg::DegreesToRadians(angle);

    double lat1 = osg::DegreesToRadians(lat_orig);
    double lon1 = osg::DegreesToRadians(lon_orig);

    osgEarth::GeoMath::destination( lat1, lon1, brng, dist, lat2, lon2 );

    lat2 = osg::RadiansToDegrees(lat2);
    lon2 = osg::RadiansToDegrees(lon2);
}

     I hope this helps in case somebody runs into the same problem I had. I hope I did not miss anything I just want to give a idea how it can be done.

     Cheers,

    Roni