106 lines
3.9 KiB
C++
106 lines
3.9 KiB
C++
/// Josh's 3D Math Library
|
|
/// A C++20 Library for 3D Math, Computer Graphics, and Scientific Computing.
|
|
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
|
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
|
/// (c) 2024 Redacted Software
|
|
/// This work is dedicated to the public domain.
|
|
|
|
/// @file Polygon.hpp
|
|
/// @desc The Polygon geometry object.
|
|
/// @edit 2024-08-01
|
|
|
|
#pragma once
|
|
|
|
#include <J3ML/Geometry/Shape.hpp>
|
|
#include <J3ML/Geometry/Forward.hpp>
|
|
#include <J3ML/LinearAlgebra.hpp>
|
|
#include <vector>
|
|
|
|
namespace J3ML::Geometry {
|
|
|
|
class Polygon : public Shape2D
|
|
{
|
|
public:
|
|
std::vector<Vector3> vertices;
|
|
|
|
/// Quickly returns an arbitrary point inside this AABB. Used in GJK intersection test.
|
|
Vector3 AnyPointFast() const;
|
|
|
|
AABB MinimalEnclosingAABB() const;
|
|
int NumVertices() const;
|
|
Vector3 Vertex(int vertexIndex) const;
|
|
Vector3 ExtremePoint(const Vector3 &direction, float &projectionDistance) const;
|
|
|
|
Vector3 ExtremePoint(const Vector3 &direction) const;
|
|
|
|
void ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const;
|
|
|
|
bool Intersects(const Capsule &capsule) const;
|
|
bool Intersects(const Line &line) const;
|
|
bool Intersects(const Ray &ray) const;
|
|
bool Intersects(const LineSegment &lineSegment) const;
|
|
bool Intersects(const Plane &plane) const;
|
|
bool Intersects(const AABB &aabb) const;
|
|
bool Intersects(const OBB &obb) const;
|
|
bool Intersects(const Triangle &triangle, float polygonThickness = 1e-3f) const;
|
|
bool Intersects(const Polygon &polygon, float polygonThickness = 1e-3f) const;
|
|
bool Intersects(const Frustum &frustum) const;
|
|
bool Intersects(const Polyhedron &polyhedron) const;
|
|
bool Intersects(const Sphere &sphere) const;
|
|
std::vector<Triangle> Triangulate() const;
|
|
/// Tests if this polygon is planar.
|
|
/** A polygon is planar if all its vertices lie on the same plane.
|
|
@note Almost all functions in this class require that the polygon is planar. While you can store vertices of
|
|
non-planar polygons in this class, they are better avoided. Read the member function documentation carefully
|
|
to avoid calling for non-planar polygons any functions which assume planarity.
|
|
@see IsConvex(), IsSimple(), IsNull(), IsFinite(), IsDegenerate(). */
|
|
bool IsPlanar(float epsilonSq = 1e-4f) const;
|
|
|
|
Vector2 MapTo2D(int i) const;
|
|
|
|
Vector2 MapTo2D(const Vector3 &point) const;
|
|
|
|
Vector3 BasisU() const;
|
|
|
|
Vector3 BasisV() const;
|
|
|
|
Plane PlaneCCW() const;
|
|
|
|
bool Contains(const Polygon &worldSpacePolygon, float polygonThickness) const;
|
|
|
|
bool Contains(const Vector3 &worldSpacePoint, float polygonThicknessSq = 1e-2f) const;
|
|
|
|
bool Contains(const LineSegment &worldSpaceLineSegment, float polygonThickness) const;
|
|
|
|
bool Contains(const Triangle &worldSpaceTriangle, float polygonThickness) const;
|
|
|
|
LineSegment Edge(int i) const;
|
|
|
|
bool ConvexIntersects(const AABB &aabb) const;
|
|
|
|
bool ConvexIntersects(const OBB &obb) const;
|
|
|
|
bool ConvexIntersects(const Frustum &frustum) const;
|
|
|
|
Vector3 MapFrom2D(const Vector2 &point) const;
|
|
|
|
bool Intersects2D(const LineSegment &segment) const;
|
|
|
|
Vector3 ClosestPoint(const LineSegment &lineSegment) const;
|
|
|
|
Vector3 ClosestPoint(const LineSegment &lineSegment, Vector3 *lineSegmentPt) const;
|
|
|
|
Vector3 ClosestPoint(const Vector3 &point) const;
|
|
|
|
/// Converts this Polygon to a Polyhedron representation.
|
|
/** This function will create a Polyhedron with two faces, one for the front face of this Polygon,
|
|
and one for the back face.
|
|
@todo Add ToPolyhedron(float polygonThickness)
|
|
@see Triangulate(), MinimalEnclosingAABB(). */
|
|
Polyhedron ToPolyhedron() const;
|
|
|
|
protected:
|
|
|
|
|
|
};
|
|
} |