Add Plane::ProjectToNegativeHalf ProjectToPositiveHalf

This commit is contained in:
2024-07-10 14:21:34 -04:00
parent c5e5958066
commit c24a352350
2 changed files with 34 additions and 5 deletions

View File

@@ -8,14 +8,17 @@ namespace J3ML::Geometry
{
using J3ML::LinearAlgebra::Vector3;
class Plane : public Shape
class Plane
{
public:
Vector3 Position;
Vector3 Normal;
float distance = 0.f;
public:
Plane() : Shape() {}
Plane() {}
/// Constructs a plane by directly specifying the normal and distance parameters.
Plane(const Vector3& normal, float d);
Plane(const Vector3& v1, const Vector3 &v2, const Vector3& v3);
Plane(const Vector3& pos, const Vector3& norm);
Plane(const Line &line, const Vector3 &normal);
@@ -82,5 +85,22 @@ namespace J3ML::Geometry
LineSegment Project(const LineSegment &segment);
Vector3 Project(const Vector3 &point) const;
/// Projects the given point to the negative half-space of this plane.
Vector3 ProjectToNegativeHalf(const Vector3& point) const;
/// Projects the given point to the positive half-space of this plane.
Vector3 ProjectToPositiveHalf(const Vector3& point) const;
bool IsParallel(const Plane& plane, float epsilon = 1e-3f) const {
return Normal.Equals(plane.Normal, epsilon);
}
/// Returns true if the two planes are equal, and their normals are oriented to the same direction.
bool Equals(const Plane& other, float epsilon = 1e-3f) const {
return IsParallel(other, epsilon) && Math::EqualAbs(distance, other.distance, epsilon);
}
};
}