Ticket #6166: XYZtoSphericalEquatorial.patch

File XYZtoSphericalEquatorial.patch, 1.6 KB (added by Arnold Metselaar <arnold.metsel@…>, 11 years ago)

Patch to add transform from cartesian to spherical equatorial in 3D.

  • strategies/strategy_transform.hpp

    diff -u -r geometry.orig/strategies/strategy_transform.hpp geometry/strategies/strategy_transform.hpp
    old new  
    251251        return false;
    252252    }
    253253
     254        template <typename P, typename T>
     255        inline bool cartesian_to_spherical_equatorial3(T x, T y, T z, P& p)
     256        {
     257                assert_dimension<P, 3>();
     258
     259                // http://en.wikipedia.org/wiki/List_of_canonical_coordinate_transformations#From_Cartesian_coordinates
     260                T const r = sqrt(x * x + y * y + z * z);
     261                set<2>(p, r);
     262                set_from_radian<0>(p, atan2(y, x));
     263                if (r > 0.0)
     264                {
     265                        set_from_radian<1>(p, asin(z / r));
     266                        return true;
     267                }
     268                return false;
     269        }
     270
    254271} // namespace detail
    255272#endif // DOXYGEN_NO_DETAIL
    256273
     
    361378    }
    362379};
    363380
     381template <typename P1, typename P2>
     382struct from_cartesian_3_to_spherical_equatorial_3
     383{
     384        inline bool apply(P1 const& p1, P2& p2) const
     385        {
     386                assert_dimension<P1, 3>();
     387                return detail::cartesian_to_spherical_equatorial3(get<0>(p1), get<1>(p1), get<2>(p1), p2);
     388        }
     389};
     390
    364391#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
    365392
    366393namespace services
     
    454481{
    455482    typedef from_cartesian_3_to_spherical_polar_3<P1, P2> type;
    456483};
     484template <typename CoordSys1, typename CoordSys2, typename P1, typename P2>
     485struct default_strategy<cartesian_tag, spherical_equatorial_tag, CoordSys1, CoordSys2, 3, 3, P1, P2>
     486{
     487        typedef from_cartesian_3_to_spherical_equatorial_3<P1, P2> type;
     488};
    457489
    458490
    459491} // namespace services