Boost logo

Geometry :

Subject: Re: [geometry] spherical_equitorial to cartesian transform confusion
From: joe_at_[hidden]
Date: 2012-08-01 22:40:20


On 2012-07-31 15:32, Barend Gehrels wrote:
>
> On 30-7-2012 3:37, joe_at_[hidden] wrote:
>> Most of the time things in my model are spherical_equatorial with
>> altitude,
>> using degrees. But it would be cool to be able to transform
>> arbitrary things in
>> my model into 3d cartesian coordinates, for example to use GGL to
>> compute the
>> straight line distance between points rather than do the trig
>> myself.
>>
>> Well I don't understand how the provided transform stuff is supposed
>> to work. I
>> get the "WTF" seen below with boost 1.50.0. If I convert various
>> spherical_equatorial points to cartesian 'distance' always returns
>> only the
>> change in altitude.
>>
>> Is what I'm trying to do actually implemented?
>>
>> ----------------------------------------
>> class MyLL { double lat, lng, alt; ... }
>>
>> BOOST_GEOMETRY_REGISTER_POINT_3D_GET_SET(MyLL, double,
>> bg::cs::spherical_equatorial<bg::degree>, get_lng, get_lat, get_alt,
>> set_lng, set_lat, set_alt)
>>
>> MyLL amsterdam(52.37, 4.90, 0);
>>
>> bg::model::point<double, 3, bg::cs::cartesian> cartesian_amsterdam;
>> bg::transform(amsterdam, cartesian_amsterdam);
>>
>> std::cout << bg::dsv(amsterdam) << std::endl; // (4.9, 52.37, 0)
>> std::cout << bg::dsv(cartesian_amsterdam) << std::endl; // WTF: (0,
>> 0, 0)
>>
>> MyLL paris(48.86, 2.35, 0);
>> bg::model::point<double, 3, bg::cs::cartesian> cartesian_paris;
>> bg::transform(paris, cartesian_paris);
>>
>> /* I expect this to return a straight line distance, a la law of
>> cosines. */
>> bg::distance(cartesian_amsterdam, cartesian_paris); )
>> /* doesn't work because transform doesn't work like I thought, but
>> ultimately I
>> * expect the result should be:
>> * double gamma = bg::distance(paris, amsterdam);
>> * double alen = EarthRadius + paris.get_alt();
>> * double blen = EarthRadius + amsterdam.get_alt();
>> * double distance = sqrt( alen*alen + blen*blen - (2*alen*blen *
>> std::cos(gamma)) );
>> */
>>
>> __
>
>
>
> I cannot yet say what is going wrong.
> But I can confirm that what you describe in the commented
> expectactions is indeed not implemented.
>
> I have to come back on this later.
>
> Regards, Barend
>

I'm just an idiot. What I was trying to do does in fact work fine if
you provide an "altitude" for the spherical-equatorial system. Obviously
that's necessary for a meaningful translation to 3d cartesian. Being
stupid, and having a lot of experience thinking about "altitude" as
relative to the earth's surface, I forgot to account for the earth's
radius.


Geometry list run by mateusz at loskot.net