]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/formulas/spherical.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / formulas / spherical.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2016, Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5
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)
9
10 #ifndef BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP
11 #define BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP
12
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>
17
18 //#include <boost/geometry/arithmetic/arithmetic.hpp>
19 #include <boost/geometry/arithmetic/cross_product.hpp>
20 #include <boost/geometry/arithmetic/dot_product.hpp>
21
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>
25
26 namespace boost { namespace geometry {
27
28 namespace formula {
29
30 template <typename Point3d, typename PointSph>
31 static inline Point3d sph_to_cart3d(PointSph const& point_sph)
32 {
33 typedef typename coordinate_type<Point3d>::type calc_t;
34
35 Point3d res;
36
37 calc_t lon = get_as_radian<0>(point_sph);
38 calc_t lat = get_as_radian<1>(point_sph);
39
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));
44
45 return res;
46 }
47
48 template <typename PointSph, typename Point3d>
49 static inline PointSph cart3d_to_sph(Point3d const& point_3d)
50 {
51 typedef typename coordinate_type<PointSph>::type coord_t;
52 typedef typename coordinate_type<Point3d>::type calc_t;
53
54 PointSph res;
55
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);
59
60 set_from_radian<0>(res, atan2(y, x));
61 set_from_radian<1>(res, asin(z));
62
63 coord_t lon = get<0>(res);
64 coord_t lat = get<1>(res);
65
66 math::normalize_spheroidal_coordinates
67 <
68 typename coordinate_system<PointSph>::type::units,
69 coord_t
70 >(lon, lat);
71
72 set<0>(res, lon);
73 set<1>(res, lat);
74
75 return res;
76 }
77
78 // -1 right
79 // 1 left
80 // 0 on
81 template <typename Point3d1, typename Point3d2>
82 static inline int sph_side_value(Point3d1 const& norm, Point3d2 const& pt)
83 {
84 typedef typename select_coordinate_type<Point3d1, Point3d2>::type calc_t;
85 calc_t c0 = 0;
86 calc_t d = dot_product(norm, pt);
87 return math::equals(d, c0) ? 0
88 : d > c0 ? 1
89 : -1; // d < 0
90 }
91
92 } // namespace formula
93
94 }} // namespace boost::geometry
95
96 #endif // BOOST_GEOMETRY_FORMULAS_SPHERICAL_HPP