3 // Copyright (c) 2016, Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP
11 #define BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP
13 #include <boost/geometry/core/coordinate_system.hpp>
14 #include <boost/geometry/core/coordinate_type.hpp>
15 #include <boost/geometry/core/access.hpp>
16 #include <boost/geometry/core/radian_access.hpp>
18 //#include <boost/geometry/arithmetic/arithmetic.hpp>
19 #include <boost/geometry/arithmetic/cross_product.hpp>
20 #include <boost/geometry/arithmetic/dot_product.hpp>
22 #include <boost/geometry/util/math.hpp>
23 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
24 #include <boost/geometry/util/select_coordinate_type.hpp>
26 namespace boost { namespace geometry {
30 template <typename Point3d, typename PointSph>
31 static inline Point3d sph_to_cart3d(PointSph const& point_sph)
33 typedef typename coordinate_type<Point3d>::type calc_t;
37 calc_t lon = get_as_radian<0>(point_sph);
38 calc_t lat = get_as_radian<1>(point_sph);
40 calc_t const cos_lat = cos(lat);
41 set<0>(res, cos_lat * cos(lon));
42 set<1>(res, cos_lat * sin(lon));
43 set<2>(res, sin(lat));
48 template <typename PointSph, typename Point3d>
49 static inline PointSph cart3d_to_sph(Point3d const& point_3d)
51 typedef typename coordinate_type<PointSph>::type coord_t;
52 typedef typename coordinate_type<Point3d>::type calc_t;
56 calc_t const x = get<0>(point_3d);
57 calc_t const y = get<1>(point_3d);
58 calc_t const z = get<2>(point_3d);
60 set_from_radian<0>(res, atan2(y, x));
61 set_from_radian<1>(res, asin(z));
63 coord_t lon = get<0>(res);
64 coord_t lat = get<1>(res);
66 math::normalize_spheroidal_coordinates
68 typename coordinate_system<PointSph>::type::units,
81 template <typename Point3d1, typename Point3d2>
82 static inline int sph_side_value(Point3d1 const& norm, Point3d2 const& pt)
84 typedef typename select_coordinate_type<Point3d1, Point3d2>::type calc_t;
86 calc_t d = dot_product(norm, pt);
87 return math::equals(d, c0) ? 0
92 } // namespace formula
94 }} // namespace boost::geometry
96 #endif // BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP