Implement Polygon::ToPolyhedron

This commit is contained in:
2024-07-10 14:19:16 -04:00
parent 2f9cb5dd87
commit 68c6f6c9f8
2 changed files with 23 additions and 2 deletions

View File

@@ -80,6 +80,14 @@ namespace J3ML::Geometry {
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:

View File

@@ -1,9 +1,9 @@
#include <J3ML/Geometry/Polygon.h>
#include <J3ML/Geometry/AABB.h>
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/Triangle.h>
#include "J3ML/Geometry/Plane.h"
#include "J3ML/Geometry/Line.h"
#include <J3ML/Algorithm/GJK.h>
#include <J3ML/Algorithm/GJK.hpp>
namespace J3ML::Geometry {
Vector3 Polygon::AnyPointFast() const { return !vertices.empty() ? vertices[0] : Vector3::NaN; }
@@ -572,6 +572,19 @@ namespace J3ML::Geometry {
return closestPt;
}
Polyhedron Polygon::ToPolyhedron() const {
Polyhedron poly;
poly.v = vertices;
poly.f.push_back(Polyhedron::Face());
poly.f.push_back(Polyhedron::Face());
for(int i = 0; i < NumVertices(); ++i)
{
poly.f[0].v.push_back(i);
poly.f[1].v.push_back(NumVertices()-1-i);
}
return poly;
}
Vector3 Polygon::ClosestPoint(const LineSegment &lineSegment) const
{
return ClosestPoint(lineSegment, 0);