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::CapsuleSDF< T > Class Template Reference

Signed distance field for a capsule (pill shape): a cylinder capped with hemispheres. More...

#include <EBGeometry_AnalyticDistanceFunctions.hpp>

Public Member Functions

 CapsuleSDF ()=default
 Default constructor. Constructs a capsule with tips at (0,-1,0) and (0,1,0), radius 0.5.
 
 CapsuleSDF (const Vec3T< T > &a_tip1, const Vec3T< T > &a_tip2, const T &a_radius) noexcept
 Full constructor.
 
 CapsuleSDF (const CapsuleSDF &)=default
 Copy constructor.
 
 CapsuleSDF (CapsuleSDF &&)=default
 Move constructor.
 
CapsuleSDF & operator= (const CapsuleSDF &)=default
 Copy assignment.
 
CapsuleSDF & operator= (CapsuleSDF &&)=default
 Move assignment.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Signed distance function for the capsule.
 
BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 The shape's axis-aligned bounding box.
 
const Vec3T< T > & getCenter1 () const noexcept
 Get the center of the first hemispherical cap.
 
const Vec3T< T > & getCenter2 () const noexcept
 Get the center of the second hemispherical cap.
 
const T & getRadius () const noexcept
 Get the radius.
 

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 hemispherical cap.
 
Vec3T< T > m_center2 = Vec3T<T>(T(0), T(0.5), T(0))
 Center of the other hemispherical cap.
 
T m_radius = T(0.5)
 Capsule radius.
 

Detailed Description

template<class T>
class EBGeometry::CapsuleSDF< T >

Signed distance field for a capsule (pill shape): a cylinder capped with hemispheres.

A capsule is defined by two outer tip positions and a radius. The tips are the outermost points of each hemispherical endcap. The total length (tip to tip) equals distance(tip1, tip2). The internal cylindrical body has length distance(tip1, tip2) - 2 * radius, and the two hemispheres each contribute a further radius to each end.

Internally the hemisphere centers are stored as m_center1 and m_center2 (inset from the tips by radius along the capsule axis). These are not the same as the tip positions passed to the constructor.

The SDF is negative inside the capsule and positive outside. By default the capsule is centered at the origin, aligned along y, with tips at (0,-1,0) and (0,1,0) and radius 0.5, giving a total height of 2 and a cylindrical body of length 1.

Template Parameters
TFloating-point precision.

Constructor & Destructor Documentation

◆ CapsuleSDF() [1/2]

template<class T >
EBGeometry::CapsuleSDF< T >::CapsuleSDF ( )
default

Default constructor. Constructs a capsule with tips at (0,-1,0) and (0,1,0), radius 0.5.

Total height = 2, cylindrical body length = 1, aligned along y, centered at origin. The stored hemisphere centers are at (0,-0.5,0) and (0,0.5,0).

◆ CapsuleSDF() [2/2]

template<class T >
EBGeometry::CapsuleSDF< T >::CapsuleSDF ( const Vec3T< T > &  a_tip1,
const Vec3T< T > &  a_tip2,
const T &  a_radius 
)
inlinenoexcept

Full constructor.

The hemisphere centers stored internally are derived from the tips: m_center1 = a_tip1 + a_radius * axis and m_center2 = a_tip2 - a_radius * axis, where axis = (a_tip2 - a_tip1) / distance(a_tip1, a_tip2). The cylindrical body length is distance(a_tip1, a_tip2) - 2 * a_radius, which must not be negative: distance(a_tip1, a_tip2) >= 2 * a_radius. At equality the capsule is a sphere.

Parameters
[in]a_tip1Outer tip of one hemispherical cap (outermost point in that direction).
[in]a_tip2Outer tip of the other hemispherical cap.
[in]a_radiusCapsule radius (applied to both the tube and the hemispherical caps).

Member Function Documentation

◆ computeBoundingVolume()

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

The shape's axis-aligned bounding box.

The two hemisphere centers plus and minus the radius along each axis.

Returns
The bounding box.

◆ getCenter1()

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

Get the center of the first hemispherical cap.

Returns
The center of the first hemispherical cap.

◆ getCenter2()

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

Get the center of the second hemispherical cap.

Returns
The center of the second hemispherical cap.

◆ getRadius()

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

Get the radius.

Returns
The radius.

◆ operator=() [1/2]

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

Move assignment.

Returns
Reference to (*this).

◆ operator=() [2/2]

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

Copy assignment.

Returns
Reference to (*this).

◆ signedDistance()

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

Signed distance function for the capsule.

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

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