| 45 | } |
| 46 | |
| 47 | std::optional<Cartographic> |
| 48 | Ellipsoid::cartesianToCartographic(const glm::dvec3& cartesian) const noexcept { |
| 49 | std::optional<glm::dvec3> p = this->scaleToGeodeticSurface(cartesian); |
| 50 | |
| 51 | if (!p) { |
| 52 | return std::optional<Cartographic>(); |
| 53 | } |
| 54 | |
| 55 | const glm::dvec3 n = this->geodeticSurfaceNormal(p.value()); |
| 56 | const glm::dvec3 h = cartesian - p.value(); |
| 57 | |
| 58 | const double longitude = glm::atan(n.y, n.x); |
| 59 | const double latitude = glm::asin(n.z); |
| 60 | const double height = Math::sign(glm::dot(h, cartesian)) * glm::length(h); |
| 61 | |
| 62 | return Cartographic(longitude, latitude, height); |
| 63 | } |
| 64 | |
| 65 | std::optional<glm::dvec3> |
| 66 | Ellipsoid::scaleToGeodeticSurface(const glm::dvec3& cartesian) const noexcept { |
no test coverage detected