cesium-native  0.41.0
Ellipsoid.h
1 #pragma once
2 
3 #include "Cartographic.h"
4 #include "Library.h"
5 
6 #include <CesiumUtility/Math.h>
7 
8 #include <glm/vec3.hpp>
9 
10 #include <optional>
11 
12 // The comments are copied here so that the doc comment always shows up in
13 // Intellisense whether the default is toggled or not.
14 #ifndef CESIUM_DISABLE_DEFAULT_ELLIPSOID
15 // To keep from breaking our API, a lot of things now need default Ellipsoid
16 // parameters. However, we shouldn't rely on these defaults internally, so
17 // disabling them is a good way to get a compile-time check that they're not
18 // being used. This macro allows us to toggle this check.
19 #define CESIUM_DEFAULT_ELLIPSOID = CesiumGeospatial::Ellipsoid::WGS84
20 #else
21 // To keep from breaking our API, a lot of things now need default Ellipsoid
22 // parameters. However, we shouldn't rely on these defaults internally, so
23 // disabling them is a good way to get a compile-time check that they're not
24 // being used. This macro allows us to toggle this check.
25 #define CESIUM_DEFAULT_ELLIPSOID
26 #endif
27 
28 namespace CesiumGeospatial {
29 
38 class CESIUMGEOSPATIAL_API Ellipsoid final {
39 public:
47  static /*constexpr*/ const Ellipsoid WGS84;
48 
52  static const Ellipsoid UNIT_SPHERE;
53 
61  constexpr Ellipsoid(double x, double y, double z) noexcept
62  : Ellipsoid(glm::dvec3(x, y, z)) {}
63 
69  constexpr Ellipsoid(const glm::dvec3& radii) noexcept
70  : _radii(radii),
71  _radiiSquared(radii.x * radii.x, radii.y * radii.y, radii.z * radii.z),
72  _oneOverRadii(1.0 / radii.x, 1.0 / radii.y, 1.0 / radii.z),
73  _oneOverRadiiSquared(
74  1.0 / (radii.x * radii.x),
75  1.0 / (radii.y * radii.y),
76  1.0 / (radii.z * radii.z)),
77  _centerToleranceSquared(CesiumUtility::Math::Epsilon1) {}
78 
82  constexpr const glm::dvec3& getRadii() const noexcept { return this->_radii; }
83 
92  glm::dvec3 geodeticSurfaceNormal(const glm::dvec3& position) const noexcept;
93 
102  glm::dvec3
103  geodeticSurfaceNormal(const Cartographic& cartographic) const noexcept;
104 
112  glm::dvec3
113  cartographicToCartesian(const Cartographic& cartographic) const noexcept;
114 
126  std::optional<Cartographic>
127  cartesianToCartographic(const glm::dvec3& cartesian) const noexcept;
128 
140  std::optional<glm::dvec3>
141  scaleToGeodeticSurface(const glm::dvec3& cartesian) const noexcept;
142 
151  std::optional<glm::dvec3>
152  scaleToGeocentricSurface(const glm::dvec3& cartesian) const noexcept;
153 
159  constexpr double getMaximumRadius() const noexcept {
160  return glm::max(this->_radii.x, glm::max(this->_radii.y, this->_radii.z));
161  }
162 
168  constexpr double getMinimumRadius() const noexcept {
169  return glm::min(this->_radii.x, glm::min(this->_radii.y, this->_radii.z));
170  }
171 
175  constexpr bool operator==(const Ellipsoid& rhs) const noexcept {
176  return this->_radii == rhs._radii;
177  };
178 
182  constexpr bool operator!=(const Ellipsoid& rhs) const noexcept {
183  return !(*this == rhs);
184  };
185 
186 private:
187  glm::dvec3 _radii;
188  glm::dvec3 _radiiSquared;
189  glm::dvec3 _oneOverRadii;
190  glm::dvec3 _oneOverRadiiSquared;
191  double _centerToleranceSquared;
192 };
193 } // namespace CesiumGeospatial
A position defined by longitude, latitude, and height.
Definition: Cartographic.h:12
A quadratic surface defined in Cartesian coordinates.
Definition: Ellipsoid.h:38
static const Ellipsoid WGS84
An Ellipsoid instance initialized to the WGS84 standard.
Definition: Ellipsoid.h:47
constexpr const glm::dvec3 & getRadii() const noexcept
Returns the radii in x-, y-, and z-direction.
Definition: Ellipsoid.h:82
std::optional< Cartographic > cartesianToCartographic(const glm::dvec3 &cartesian) const noexcept
Converts the provided cartesian to a Cartographic representation.
constexpr double getMinimumRadius() const noexcept
The minimum radius in any dimension.
Definition: Ellipsoid.h:168
glm::dvec3 cartographicToCartesian(const Cartographic &cartographic) const noexcept
Converts the provided Cartographic to cartesian representation.
glm::dvec3 geodeticSurfaceNormal(const Cartographic &cartographic) const noexcept
Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
constexpr bool operator!=(const Ellipsoid &rhs) const noexcept
Returns true if two elliposids are not equal.
Definition: Ellipsoid.h:182
constexpr bool operator==(const Ellipsoid &rhs) const noexcept
Returns true if two elliposids are equal.
Definition: Ellipsoid.h:175
constexpr Ellipsoid(double x, double y, double z) noexcept
Creates a new instance.
Definition: Ellipsoid.h:61
constexpr double getMaximumRadius() const noexcept
The maximum radius in any dimension.
Definition: Ellipsoid.h:159
static const Ellipsoid UNIT_SPHERE
An Ellipsoid with all three radii set to one meter.
Definition: Ellipsoid.h:52
std::optional< glm::dvec3 > scaleToGeocentricSurface(const glm::dvec3 &cartesian) const noexcept
Scales the provided cartesian position along the geocentric surface normal so that it is on the surfa...
constexpr Ellipsoid(const glm::dvec3 &radii) noexcept
Creates a new instance.
Definition: Ellipsoid.h:69
std::optional< glm::dvec3 > scaleToGeodeticSurface(const glm::dvec3 &cartesian) const noexcept
Scales the given cartesian position along the geodetic surface normal so that it is on the surface of...
glm::dvec3 geodeticSurfaceNormal(const glm::dvec3 &position) const noexcept
Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
static constexpr double Epsilon1
0.1
Definition: Math.h:15
Classes for geospatial computations in Cesium.