src/utilities/geometry/Plane.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_GEOMETRY_PLANE_HPP | ||
| 7 | #define UTILITIES_GEOMETRY_PLANE_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | #include "../core/Logger.hpp" | ||
| 11 | |||
| 12 | #include <boost/optional.hpp> | ||
| 13 | |||
| 14 | #include <vector> | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | // forward declaration | ||
| 19 | class Point3d; | ||
| 20 | class Vector3d; | ||
| 21 | |||
| 22 | /** Plane defines an infinite plane in 3D space. The equation of a plane is | ||
| 23 | * a*x + b*y + c*z + d = 0, any point that satisfies this equation is on the plane. | ||
| 24 | */ | ||
| 25 | class UTILITIES_API Plane | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | /// construct with point and outward normal, throws openstudio::Exception if outwardNormal has 0 length. | ||
| 29 | Plane(const Point3d& point, const Vector3d& outwardNormal); | ||
| 30 | |||
| 31 | /// construct with points, will fit least squares plane. | ||
| 32 | /// attempts to align outward normal with that of the points (according to right hand rule). | ||
| 33 | /// throws openstudio::Exception if cannot compute plane for these points. | ||
| 34 | Plane(const std::vector<Point3d>& points); | ||
| 35 | |||
| 36 | // Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them | ||
| 37 | // There's no need to check if the length of the normal is zero since we never allow another plane to not satisfy this condition | ||
| 38 | Plane(const Plane& other) = default; | ||
| 39 | Plane(Plane&& other) noexcept = default; | ||
| 40 | Plane& operator=(const Plane&) = default; | ||
| 41 | Plane& operator=(Plane&&) noexcept = default; | ||
| 42 | // ~Plane() noexcept = default; | ||
| 43 | |||
| 44 | /// get the outward normal of this plane | ||
| 45 | Vector3d outwardNormal() const; | ||
| 46 | |||
| 47 | /// is this plane parallel to the other plane | ||
| 48 | /// true if absolute value of dot product of outward normals is >= (1-tol) | ||
| 49 | bool parallel(const Plane& other, double tol = 0.001) const; | ||
| 50 | |||
| 51 | /// is this plane equal to the other plane | ||
| 52 | /// true if dot product of outward normals is >= (1-tol) and abs(d1-d2) <= tol | ||
| 53 | bool equal(const Plane& other, double tol = 0.001) const; | ||
| 54 | |||
| 55 | /// is this plane reverse equal to the other plane | ||
| 56 | /// true if dot product of outward normals is <= (-1+tol) and abs(d1+d2) <= tol | ||
| 57 | bool reverseEqual(const Plane& other, double tol = 0.001) const; | ||
| 58 | |||
| 59 | /// flip the plane so outward normal is opposite | ||
| 60 | Plane reversePlane() const; | ||
| 61 | |||
| 62 | /// project a point to this plane | ||
| 63 | Point3d project(const Point3d& point) const; | ||
| 64 | |||
| 65 | /// project a vector of points to this plane | ||
| 66 | std::vector<Point3d> project(const std::vector<Point3d>& points) const; | ||
| 67 | |||
| 68 | /// returns true if the point is on this plane | ||
| 69 | bool pointOnPlane(const Point3d& point, double tol = 0.001) const; | ||
| 70 | |||
| 71 | /// coefficient a | ||
| 72 | double a() const; | ||
| 73 | |||
| 74 | /// coefficient b | ||
| 75 | double b() const; | ||
| 76 | |||
| 77 | /// coefficient c | ||
| 78 | double c() const; | ||
| 79 | |||
| 80 | /// coefficient d | ||
| 81 | double d() const; | ||
| 82 | |||
| 83 | // Returns any Point3d that's on this plane | ||
| 84 | Point3d anyPointOnPlane() const; | ||
| 85 | |||
| 86 | /** Project a directed ray towards a plane and returns the intersection point if any. The RayDirection should be shooting TOWARDS the plane | ||
| 87 | * If enforceDirectionOfPlane is true, the ray direction and the plane outward normal must be facing each other */ | ||
| 88 | boost::optional<Point3d> rayIntersection(const Point3d& rayOrigin, const Vector3d& rayDirection, bool enforceDirectionOfPlane = false) const; | ||
| 89 | |||
| 90 | private: | ||
| 91 | // construct with coefficients | ||
| 92 | Plane(double a, double b, double c, double d); | ||
| 93 | |||
| 94 | − | REGISTER_LOGGER("utilities.Plane"); | |
| 95 | |||
| 96 | double m_a; | ||
| 97 | double m_b; | ||
| 98 | double m_c; | ||
| 99 | double m_d; | ||
| 100 | }; | ||
| 101 | |||
| 102 | /// ostream operator | ||
| 103 | UTILITIES_API std::ostream& operator<<(std::ostream& os, const Plane& plane); | ||
| 104 | |||
| 105 | /// optional Plane | ||
| 106 | using OptionalPlane = boost::optional<Plane>; | ||
| 107 | |||
| 108 | /// vector of Plane | ||
| 109 | using PlaneVector = std::vector<Plane>; | ||
| 110 | |||
| 111 | } // namespace openstudio | ||
| 112 | |||
| 113 | #endif //UTILITIES_GEOMETRY_BOUNDINGBOX_HPP | ||
| 114 |