OGLplus  (0.59.0) a C++ wrapper for rendering APIs

coordinates.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_COORDINATES_HPP
9 #define EAGINE_MATH_COORDINATES_HPP
10 
11 #include "../quantities.hpp"
12 #include "../valid_if/nonnegative.hpp"
13 #include "../valid_if/positive.hpp"
14 #include "functions.hpp"
15 #include "vector.hpp"
16 #include <tuple>
17 
18 namespace eagine::math {
19 //------------------------------------------------------------------------------
22 template <typename T, bool V>
24 public:
26  constexpr unit_spherical_coordinate() noexcept = default;
27 
31  radians_t<T> elevation) noexcept
32  : _azim{azimuth}
33  , _elev{elevation} {}
34 
36  auto azimuth() const noexcept -> radians_t<T> {
37  return _azim;
38  }
39 
41  auto elevation() const noexcept -> radians_t<T> {
42  return _elev;
43  }
44 
45 private:
46  radians_t<T> _azim{T(0)};
47  radians_t<T> _elev{T(0)};
48 };
49 //------------------------------------------------------------------------------
52 template <typename T, bool V>
54  -> vector<T, 3, V> {
55  using std::abs;
56  return vector<T, 3, V>::make(
57  cos(c.azimuth()) * abs(cos(c.elevation())),
58  sin(c.elevation()),
59  -sin(c.azimuth()) * abs(cos(c.elevation())));
60 }
61 //------------------------------------------------------------------------------
64 template <typename T, bool V>
68  using std::abs;
69  return abs(v.y()) > T(0) ? R(-arctan(v.z(), v.x()), arcsin(v.y()))
70  : R(radians_t<T>(0), arcsin(v.y()));
71 }
72 //------------------------------------------------------------------------------
73 } // namespace eagine::math
74 
75 #endif // EAGINE_MATH_COORDINATES_HPP
auto to_unit_spherical(vector< T, 3, V > v) noexcept -> unit_spherical_coordinate< T, V >
Converts cartesian vector to unit spherical coordinate.
Definition: coordinates.hpp:65
constexpr unit_spherical_coordinate(radians_t< T > azimuth, radians_t< T > elevation) noexcept
Constructor initializing the azimuth and elevation.
Definition: coordinates.hpp:29
auto to_cartesian(unit_spherical_coordinate< T, V > c) noexcept -> vector< T, 3, V >
Converts unit spherical coordinate to cartesian vector.
Definition: coordinates.hpp:53
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
Class representing unit spherical coordinate.
Definition: coordinates.hpp:23
auto azimuth() const noexcept -> radians_t< T >
Returns the azimuth.
Definition: coordinates.hpp:36
auto elevation() const noexcept -> radians_t< T >
Returns the elevation.
Definition: coordinates.hpp:41
constexpr unit_spherical_coordinate() noexcept=default
Default constructor.
Value of type T with a specified unit or tag type U.
Definition: tagged_quantity.hpp:27

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).