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

Signed distance field for a regular prism: a regular polygon of n sides, extruded between two end centers. More...

#include <EBGeometry_AnalyticDistanceFunctions.hpp>

Public Member Functions

 PolygonPrismSDF ()=default
 Default constructor. Constructs a hexagonal prism from (0,-0.5,0) to (0,0.5,0), of circumradius 1, with a vertex along x.
 
 PolygonPrismSDF (const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_radius, const unsigned a_sides, const Vec3T< T > &a_vertexDirection)
 Full constructor.
 
 PolygonPrismSDF (const PolygonPrismSDF &)=default
 Copy constructor.
 
 PolygonPrismSDF (PolygonPrismSDF &&)=default
 Move constructor.
 
PolygonPrismSDF & operator= (const PolygonPrismSDF &)=default
 Copy assignment.
 
PolygonPrismSDF & operator= (PolygonPrismSDF &&)=default
 Move assignment.
 
const Vec3T< T > & getCenter1 () const noexcept
 Get the center of one end.
 
const Vec3T< T > & getCenter2 () const noexcept
 Get the center of the other end.
 
const T & getRadius () const noexcept
 Get the circumradius.
 
unsigned getSides () const noexcept
 Get the number of sides.
 
const Vec3T< T > & getVertexDirection () const noexcept
 Get the unit direction from the axis toward the first vertex, across the axis.
 
T polygonDistance (const T a_u, const T a_v) const noexcept
 The signed distance to the polygon in the cross-section, at coordinates a_u along the vertex direction and a_v across it.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Signed distance function for the prism.
 
uint32_t getNumParts () const noexcept
 How many parts the shape has (see hasParts): the sides and the two caps, getSides() + 2.
 
uint32_t closestPart (const Vec3T< T > &a_point) const noexcept
 The part whose term decides the value at a point (see hasParts): the side k from 0 to getSides() - 1, counted from the first vertex around the axis; then getSides() for the cap at the first center and getSides() + 1 for the one at the second.
 
BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 The shape's axis-aligned bounding box.
 

Static Public Attributes

static constexpr DistanceQuality distanceQuality = DistanceQuality::Exact
 How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface.
 

Protected Attributes

Vec3T< T > m_center1 = Vec3T<T>(T(0), T(-0.5), T(0))
 Center of one end.
 
Vec3T< T > m_center2 = Vec3T<T>(T(0), T(0.5), T(0))
 Center of the other end.
 
Vec3T< T > m_axis = Vec3T<T>(T(0), T(1), T(0))
 Unit axis from m_center1 to m_center2.
 
Vec3T< T > m_vertex = Vec3T<T>(T(1), T(0), T(0))
 Unit direction from the axis toward the first vertex.
 
Vec3T< T > m_side = Vec3T<T>(T(0), T(0), T(-1))
 Unit direction across the axis and m_vertex, cross(m_axis, m_vertex).
 
T m_length = T(1)
 Distance between the end centers.
 
T m_radius = T(1)
 Circumradius.
 
unsigned m_sides = 6U
 Number of sides.
 

Detailed Description

template<class T>
class EBGeometry::PolygonPrismSDF< T >

Signed distance field for a regular prism: a regular polygon of n sides, extruded between two end centers.

The polygon's circumradius (the distance from the axis to a vertex) is the radius given, and one vertex points along the given direction, across the axis. The distance is exact: in the cross-section, the point is turned into the polygon's first sector, where the distance to the regular polygon is that to one edge (Quilez's regular polygon), and the extrusion between the end planes is exact too. Three sides make a triangular prism, four a square one, six a hexagonal rod. Round its edges with Offset of a slightly smaller prism. By default the prism is a hexagonal one from (0,-0.5,0) to (0,0.5,0), of circumradius 1, with a vertex along x.

Template Parameters
TFloating-point precision.

Constructor & Destructor Documentation

◆ PolygonPrismSDF()

template<class T >
EBGeometry::PolygonPrismSDF< T >::PolygonPrismSDF ( const Vec3T< T > &  a_center1,
const Vec3T< T > &  a_center2,
const T  a_radius,
const unsigned  a_sides,
const Vec3T< T > &  a_vertexDirection 
)
inline

Full constructor.

Parameters
[in]a_center1Center of one end.
[in]a_center2Center of the other end; it must differ from a_center1.
[in]a_radiusCircumradius: the distance from the axis to a vertex, finite and positive.
[in]a_sidesNumber of sides, at least 3.
[in]a_vertexDirectionDirection from the axis toward one vertex. Only its part across the axis is used, and that must not be zero.

Member Function Documentation

◆ closestPart()

template<class T >
uint32_t EBGeometry::PolygonPrismSDF< T >::closestPart ( const Vec3T< T > &  a_point) const
inlinenoexcept

The part whose term decides the value at a point (see hasParts): the side k from 0 to getSides() - 1, counted from the first vertex around the axis; then getSides() for the cap at the first center and getSides() + 1 for the one at the second.

Parameters
[in]a_pointPosition.
Returns
The part.

◆ computeBoundingVolume()

template<class T >
BoundingVolumes::AABBT< T > EBGeometry::PolygonPrismSDF< T >::computeBoundingVolume ( ) const
inlinenoexcept

The shape's axis-aligned bounding box.

The box around the circumscribed cylinder: along axis i, each end reaches the circumradius times sqrt(1 - axis_i^2) beyond its center.

Returns
The bounding box.

◆ getCenter1()

template<class T >
const Vec3T< T > & EBGeometry::PolygonPrismSDF< T >::getCenter1 ( ) const
inlinenoexcept

Get the center of one end.

Returns
m_center1.

◆ getCenter2()

template<class T >
const Vec3T< T > & EBGeometry::PolygonPrismSDF< T >::getCenter2 ( ) const
inlinenoexcept

Get the center of the other end.

Returns
m_center2.

◆ getNumParts()

template<class T >
uint32_t EBGeometry::PolygonPrismSDF< T >::getNumParts ( ) const
inlinenoexcept

How many parts the shape has (see hasParts): the sides and the two caps, getSides() + 2.

Returns
The count.

◆ getRadius()

template<class T >
const T & EBGeometry::PolygonPrismSDF< T >::getRadius ( ) const
inlinenoexcept

Get the circumradius.

Returns
m_radius.

◆ getSides()

template<class T >
unsigned EBGeometry::PolygonPrismSDF< T >::getSides ( ) const
inlinenoexcept

Get the number of sides.

Returns
m_sides.

◆ getVertexDirection()

template<class T >
const Vec3T< T > & EBGeometry::PolygonPrismSDF< T >::getVertexDirection ( ) const
inlinenoexcept

Get the unit direction from the axis toward the first vertex, across the axis.

Returns
m_vertex.

◆ operator=() [1/2]

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

Copy assignment.

Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T >
PolygonPrismSDF & EBGeometry::PolygonPrismSDF< T >::operator= ( PolygonPrismSDF< T > &&  )
default

Move assignment.

Returns
Reference to (*this).

◆ polygonDistance()

template<class T >
T EBGeometry::PolygonPrismSDF< T >::polygonDistance ( const T  a_u,
const T  a_v 
) const
inlinenoexcept

The signed distance to the polygon in the cross-section, at coordinates a_u along the vertex direction and a_v across it.

Parameters
[in]a_uCoordinate along the direction toward the first vertex.
[in]a_vCoordinate along the other direction across the axis.
Returns
The signed distance to the polygon.

◆ signedDistance()

template<class T >
T EBGeometry::PolygonPrismSDF< T >::signedDistance ( const Vec3T< T > &  a_point) const
inlinenoexcept

Signed distance function for the prism.

Parameters
[in]a_pointPosition.
Returns
Signed distance from a_point to the prism surface; negative inside.

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