EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
EBGeometry::Polygon2D< T > Class Template Reference

Class for embedding a polygon face into 2D. More...

#include <EBGeometry_Polygon2D.hpp>

Public Types

enum class  InsideOutsideAlgorithm { SubtendedAngle , CrossingNumber , WindingNumber }
 Supported algorithms for performing inside/outside tests when checking if a point projects to the inside or outside of a polygon face. More...
 
using Vec2 = Vec2T< T >
 Alias for the 2D vector type used for the projected polygon points.
 
using Vec3 = Vec3T< T >
 Alias for the 3D vector type used for the polygon's original (unprojected) points.
 

Public Member Functions

 Polygon2D ()=delete
 Disallowed constructor, use the one with the normal vector and points.
 
 Polygon2D (const Vec3 &a_normal, const std::vector< Vec3 > &a_points)
 Full constructor.
 
 Polygon2D (const Polygon2D &a_other)=default
 Copy constructor.
 
 Polygon2D (Polygon2D &&a_other) noexcept=default
 Move constructor.
 
 ~Polygon2D ()=default
 Destructor.
 
Polygon2Doperator= (const Polygon2D &a_other)=default
 Copy assignment operator.
 
Polygon2Doperator= (Polygon2D &&a_other) noexcept=default
 Move assignment operator.
 
bool isPointInside (const Vec3 &a_point, const InsideOutsideAlgorithm a_algorithm) const noexcept
 Check if a point is inside or outside the 2D polygon.
 
bool isPointInsidePolygonWindingNumber (const Vec3 &a_point) const noexcept
 Check if a point is inside a 2D polygon, using the winding number algorithm.
 
bool isPointInsidePolygonSubtend (const Vec3 &a_point) const noexcept
 Check if a point is inside a 2D polygon, using the subtended angles.
 
bool isPointInsidePolygonCrossingNumber (const Vec3 &a_point) const noexcept
 Check if a point is inside a 2D polygon, by computing the number of times a ray crosses the polygon edges.
 

Detailed Description

template<class T>
class EBGeometry::Polygon2D< T >

Class for embedding a polygon face into 2D.

This class is required for determining whether or not a 3D point projected to the plane of an N-sided polygon lies inside or outside the polygon face. To do this we compute the 2D embedding of the polygon face, reducing the problem to a tractable dimension where we can use well-tested algorithm. The 2D embedding of a polygon occurs by taking a set of 3D points and a corresponding normal vector, and projecting those points along one of the 3D Cartesian axes such that the polygon has the largest area. In essence, we simply find the direction with the smallest normal vector component and ignore that. Once the 2D embedding is computed, we can use well-known algorithms for checking if a point lies inside or outside. The supported algorithms are 1) The winding number algorithm (computing the winding number), 2) Computing the subtended angle of the point with the edges of the polygon (sums to 360 degrees if the point is inside), or computing the crossing number which checks how many times a ray cast from the point crosses the edges of the polygon.

Template Parameters
TFloating-point precision.

Member Enumeration Documentation

◆ InsideOutsideAlgorithm

Supported algorithms for performing inside/outside tests when checking if a point projects to the inside or outside of a polygon face.

Enumerator
SubtendedAngle 

Sums the subtended angle of the point with each polygon edge; the point is inside if the sum is +-2*pi (360 degrees) and outside if it is 0. See isPointInsidePolygonSubtend() and computeSubtendedAngle().

CrossingNumber 

Casts a ray from the point along +x and counts how many times it crosses a polygon edge; the point is inside if the crossing count is odd (even-odd rule). See isPointInsidePolygonCrossingNumber() and computeCrossingNumber().

WindingNumber 

Computes the winding number of the polygon boundary around the point; the point is inside if the winding number is non-zero. See isPointInsidePolygonWindingNumber() and computeWindingNumber().

Constructor & Destructor Documentation

◆ Polygon2D() [1/3]

template<class T >
EBGeometry::Polygon2D< T >::Polygon2D ( const Vec3 a_normal,
const std::vector< Vec3 > &  a_points 
)

Full constructor.

Parameters
[in]a_normalNormal vector of the 3D polygon face. Must be finite and non-degenerate (length > 0).
[in]a_pointsVertex coordinates of the 3D polygon face. Must have at least 3 points.

◆ Polygon2D() [2/3]

template<class T >
EBGeometry::Polygon2D< T >::Polygon2D ( const Polygon2D< T > &  a_other)
default

Copy constructor.

Parameters
[in]a_otherOther polygon.

◆ Polygon2D() [3/3]

template<class T >
EBGeometry::Polygon2D< T >::Polygon2D ( Polygon2D< T > &&  a_other)
defaultnoexcept

Move constructor.

Parameters
[in,out]a_otherOther polygon.

Member Function Documentation

◆ isPointInside()

template<class T >
bool EBGeometry::Polygon2D< T >::isPointInside ( const Vec3 a_point,
const InsideOutsideAlgorithm  a_algorithm 
) const
inlinenoexcept

Check if a point is inside or outside the 2D polygon.

Parameters
[in]a_point3D point coordinates.
[in]a_algorithmInside/outside algorithm to use.

This will call the function corresponding to a_algorithm.

Returns
True if the projected point lies inside the 2D polygon.

◆ isPointInsidePolygonCrossingNumber()

template<class T >
bool EBGeometry::Polygon2D< T >::isPointInsidePolygonCrossingNumber ( const Vec3 a_point) const
inlinenoexcept

Check if a point is inside a 2D polygon, by computing the number of times a ray crosses the polygon edges.

Parameters
[in]a_point3D point coordinates
Returns
Returns true if the 3D point projects to the inside of the 2D polygon

◆ isPointInsidePolygonSubtend()

template<class T >
bool EBGeometry::Polygon2D< T >::isPointInsidePolygonSubtend ( const Vec3 a_point) const
inlinenoexcept

Check if a point is inside a 2D polygon, using the subtended angles.

Parameters
[in]a_point3D point coordinates
Returns
Returns true if the 3D point projects to the inside of the 2D polygon

◆ isPointInsidePolygonWindingNumber()

template<class T >
bool EBGeometry::Polygon2D< T >::isPointInsidePolygonWindingNumber ( const Vec3 a_point) const
inlinenoexcept

Check if a point is inside a 2D polygon, using the winding number algorithm.

Parameters
[in]a_point3D point coordinates
Returns
Returns true if the 3D point projects to the inside of the 2D polygon

◆ operator=() [1/2]

template<class T >
Polygon2D & EBGeometry::Polygon2D< T >::operator= ( const Polygon2D< T > &  a_other)
default

Copy assignment operator.

Parameters
[in]a_otherOther polygon.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T >
Polygon2D & EBGeometry::Polygon2D< T >::operator= ( Polygon2D< T > &&  a_other)
defaultnoexcept

Move assignment operator.

Parameters
[in,out]a_otherOther polygon.
Returns
Reference to (*this).

The documentation for this class was generated from the following file: