#pragma once #include "mcc_coord.h" namespace mcc { class MccProhibitedZone { public: virtual ~MccProhibitedZone() = default; bool inZone(this auto&& self, const MccCoordinate& x, const MccCoordinate& y) { return std::forward(self).inZoneImpl(x, y); } protected: bool inZoneImpl(const MccCoordinate&, const MccCoordinate&) { return false; } }; class MccMinAltPZ : public MccProhibitedZone { public: MccMinAltPZ(const MccCoordinate& min_alt) : _minAlt(min_alt) {} MccCoordinate minAlt() const { return _minAlt; } private: double _minAlt; bool inZoneImpl(const MccCoordinate& alt, const MccCoordinate&) { return alt <= _minAlt; } }; class MccMaxAltPZ { public: MccMaxAltPZ(double max_alt) : _maxAlt(max_alt) {} double maxAlt() const { return _maxAlt; } private: double _maxAlt; bool inZoneImpl(const MccCoordinate& alt, const MccCoordinate&) { return alt >= _maxAlt; } }; /* * a general planar ellipse equation: * A*(x-xc)^2 + B*(x-xc)(y-yc) + C*(y-yc)^2 = 1 * * A = cos(t)^2/a^2 + sin(t)^2/b^2 * B = sin(2*t)/a^2 - sin(2*t)/b^2 * C = cos(t)^2/b^2 + sin(t)^2/a^2 * * t - angle between X-axis and big semi-axis (a) * * * Ellipse on unit sphere (Az, Alt): * x^2/a^2 + y^2/b^2 = 1, * where a = tan(alpha), b = tan(beta), * a and b - big and small spherical semi-axis * also: * let delta is a spherical distance between ellipse focuses, then * d = tan(delta) and b^2 = (a^2 - d^2)/(1 + d^2) * * tangent coordinates: * x = tan(Az) * y = tan(Alt)*sqrt(1+tan(Az)^2) * * * -------------------------------------------- * * let P - point with (Az_P, Zd_P), * (Az_C, Zd_C) - center of ellipse, a and b big and small semi-axis, * vec_a and vec_b - unit vectors along a an b (it lie in tangent surface to point C!!!), then * * ((vec_P-vec_C)*vec_b)^2/a^2 + ((vec_P-vec_C)*vec_b)^2/b^2 <= 1.0 * {((vec_P-vec_C)*vec_b)^2/tan(a)^2 + ((vec_P-vec_C)*vec_b)^2/tan(b)^2 <= 1.0} * * - dot-product * * vec_P = (sin(Zd_P)*cos(Az_P), sin(Zd_P)*sin(Az_P), cos(Zd_P)) * vec_C = (sin(Zd_C)*cos(Az_C), sin(Zd_C)*sin(Az_C), cos(Zd_C)) * */ class MccEllipsePZ { public: MccEllipsePZ(const MccCoordinate& xc, const MccCoordinate& yc, const MccCoordinate& a, const MccCoordinate& b, const MccCoordinate& theta = 0.0) : _xc(xc), _yc(yc), _a(a), _b(b), _theta(theta), _tanXc(std::tan(xc)), _tanYc(std::tan(yc)) { _tanYc *= std::sqrt(1.0 + _tanXc * _tanXc); auto _tan2A = tan(a); auto _tan2B = tan(b); _tan2A *= _tan2A; _tan2B *= _tan2B; auto ct = cos(theta); auto ct2 = ct * ct; auto st = sin(theta); auto st2 = st * st; auto sin2t = sin(2.0 * theta); cxx = ct2 / _tan2A + st2 / _tan2B; cyy = st2 / _tan2A + ct2 / _tan2B; cxy = sin2t / _tan2A - sin2t / _tan2B; } // circle MccEllipsePZ(const MccCoordinate& xc, const MccCoordinate& yc, const MccCoordinate& a) : mcc::MccEllipsePZ(xc, yc, a, a) { } private: double _xc, _yc, _a, _b, _theta; double _tanXc, _tanYc, cxx, cxy, cyy; bool inZoneImpl(const MccCoordinate& x, const MccCoordinate& y) { auto tanX = tan(x); auto tanY = tan(y) * sqrt(1.0 + tanX * tanX); auto xr = tanX - _tanXc; auto yr = tanY - _tanYc; return (cxx * xr * xr + cxy * xr * yr + cyy * yr * yr) <= 1.0; } }; } // namespace mcc