Skip to content

File PolygonalFieldOfView.hpp

File List > astrea > trace > trace > platforms > sensors > fov > instances > PolygonalFieldOfView.hpp

Go to the documentation of this file

#pragma once

#include <numbers>
#include <vector>

#include <gtl/btree.hpp>

#include <astro/astro.fwd.hpp>
#include <astro/frames/dynamic_frames.hpp>
#include <units/units.hpp>

#include <trace/platforms/sensors/fov/FieldOfView.hpp>

namespace astrea {
namespace trace {

class PolygonalFieldOfView : public FieldOfView {
  public:
    PolygonalFieldOfView(const Angle& halfConeAngle = std::numbers::pi / 4.0 * mp_units::angular::unit_symbols::rad, const int& nPoints = 72);

    PolygonalFieldOfView(const Angle& halfConeWidth, const Angle& halfConeHeight, const int& nPoints = 72);

    PolygonalFieldOfView(const gtl::btree_map<Angle, Angle>& points) :
        _points(points)
    {
        find_min_and_max_angles();
    }

    ~PolygonalFieldOfView() = default;

    bool contains(
        const astro::CartesianVector<Distance, astro::frames::earth::icrf>& boresight,
        const astro::CartesianVector<Distance, astro::frames::earth::icrf>& target
    ) const;

  private:
    // TODO: These angle are actually defined w.r.t a frame so we need to figure out what that
    // is and how to define it meaningfully. It might have to come from a FrameReference object
    // Probably will be some body-fixed frame aligned with the sensor boresight
    // The key angle is the azimuthal angle around the boresight, and the value angle is the
    // off-boresight angle at that azimuth
    gtl::btree_map<Angle, Angle> _points; //<! Map of angles defining the polygonal field of view
    Angle _minHalfAngle = 0.0 * mp_units::angular::unit_symbols::rad; //<! Minimum off-boresight half angle
    Angle _maxHalfAngle = std::numeric_limits<Angle>::infinity();     //<! Maximum off-boresight half angle

    void find_min_and_max_angles();

    std::vector<std::pair<Unitless, Unitless>> build_polygon() const;
};

bool point_in_polygon(const std::pair<Unitless, Unitless>& point, const std::vector<std::pair<Unitless, Unitless>>& polygon);

} // namespace trace
} // namespace astrea