// Boost.Geometry // Copyright (c) 2021, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_STRATEGY_SPHERICAL_AREA_BOX_HPP #define BOOST_GEOMETRY_STRATEGY_SPHERICAL_AREA_BOX_HPP #include #include #include #include #include #include #include namespace boost { namespace geometry { namespace strategy { namespace area { // https://math.stackexchange.com/questions/131735/surface-element-in-spherical-coordinates // http://www.cs.cmu.edu/afs/cs/academic/class/16823-s16/www/pdfs/appearance-modeling-3.pdf // https://www.astronomyclub.xyz/celestial-sphere-2/solid-angle-on-the-celestial-sphere.html // https://mathworld.wolfram.com/SolidAngle.html // https://en.wikipedia.org/wiki/Spherical_coordinate_system // Note that the equations used in the above articles are spherical polar coordinates. // We use spherical equatorial, so the equation is different: // assume(y_max > y_min); // assume(x_max > x_min); // /* because of polar to equatorial conversion */ // sin(%pi / 2 - y); // O: r ^ 2 * cos(y); // S: integrate(integrate(O, y, y_min, y_max), x, x_min, x_max); template < typename RadiusTypeOrSphere = double, typename CalculationType = void > class spherical_box { typedef typename strategy_detail::get_radius < RadiusTypeOrSphere >::type radius_type; public: template struct result_type : strategy::area::detail::result_type < Box, CalculationType > {}; // For consistency with other strategies the radius is set to 1 inline spherical_box() : m_radius(1.0) {} template explicit inline spherical_box(RadiusOrSphere const& radius_or_sphere) : m_radius(strategy_detail::get_radius < RadiusOrSphere >::apply(radius_or_sphere)) {} template inline auto apply(Box const& box) const { typedef typename result_type::type return_type; return_type x_min = get_as_radian(box); // lon return_type y_min = get_as_radian(box); // lat return_type x_max = get_as_radian(box); return_type y_max = get_as_radian(box); if (x_min == x_max || y_max == y_min) { return return_type(0); } math::normalize_spheroidal_box_coordinates(x_min, y_min, x_max, y_max); return (x_max - x_min) * (sin(y_max) - sin(y_min)) * return_type(m_radius * m_radius); } srs::sphere model() const { return srs::sphere(m_radius); } private: radius_type m_radius; }; }} // namespace strategy::area }} // namespace boost::geometry #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_AREA_BOX_HPP