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

Signed distance field for a helical tube: a spring, a coil or a thread, with rounded ends. More...

#include <EBGeometry_AnalyticDistanceFunctions.hpp>

Public Member Functions

 HelixSDF ()=default
 Default constructor. Constructs a helix from (0,-1,0) to (0,1,0) in 4 turns of radius 0.5, starting along x, with a tube radius of 0.1.
 
 HelixSDF (const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T a_helixRadius, const T a_turns, const T a_tubeRadius, const Vec3T< T > &a_startDirection)
 Full constructor.
 
 HelixSDF (const HelixSDF &)=default
 Copy constructor.
 
 HelixSDF (HelixSDF &&)=default
 Move constructor.
 
HelixSDF & operator= (const HelixSDF &)=default
 Copy assignment.
 
HelixSDF & operator= (HelixSDF &&)=default
 Move assignment.
 
const Vec3T< T > & getCenter1 () const noexcept
 Get the axis point at the first end.
 
const Vec3T< T > & getCenter2 () const noexcept
 Get the axis point at the second end.
 
const T & getHelixRadius () const noexcept
 Get the helix radius.
 
const T & getTurns () const noexcept
 Get the number of turns.
 
const T & getTubeRadius () const noexcept
 Get the tube radius.
 
const Vec3T< T > & getStartDirection () const noexcept
 Get the unit direction from the axis to the center line at the first end.
 
Vec3T< T > centerLine (const T a_angle) const noexcept
 Get the point on the center line at a helix angle.
 
T signedDistance (const Vec3T< T > &a_point) const noexcept
 Signed distance function for the helix.
 
BoundingVolumes::AABBT< T > computeBoundingVolume () const noexcept
 The shape's axis-aligned bounding box: that of the cylinder the tube fits in.
 

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 Member Functions

T windowMinimum (const T a_k, const T a_rho, const T a_phi, const T a_y, const T a_rate, const T a_last) const noexcept
 The smallest squared distance from a point to the center line over one window of helix angles, phi + 2 pi k + s with |s| <= pi, cut to the helix' angles.
 

Protected Attributes

Vec3T< T > m_center1 = Vec3T<T>(T(0), T(-1), T(0))
 The axis point at the first end.
 
Vec3T< T > m_center2 = Vec3T<T>(T(0), T(1), T(0))
 The axis point at the second end.
 
Vec3T< T > m_axis = Vec3T<T>(T(0), T(1), T(0))
 Unit axis from m_center1 to m_center2.
 
Vec3T< T > m_start = Vec3T<T>(T(1), T(0), T(0))
 Unit direction to the center line at the first end.
 
T m_helixRadius = T(0.5)
 The helix radius.
 
T m_turns = T(4)
 The number of turns.
 
T m_tubeRadius = T(0.1)
 The tube's radius.
 

Detailed Description

template<class T>
class EBGeometry::HelixSDF< T >

Signed distance field for a helical tube: a spring, a coil or a thread, with rounded ends.

The tube's center line is a right-handed helix around the axis from the first end center to the second, starting from the first in the given direction across the axis; Reflect makes a left-handed one. The value is the distance to the center line less the tube's radius, exact. The squared distance to the line, as a function of the helix angle, is searched turn by turn, in windows of one turn centered on the point's own angle: in each, it has at most one minimum inside, where its derivative increases, which Newton steps kept in a bracket find; the window's ends and the helix' ends are the other candidates. The search starts at the turn nearest the point's height and goes outward while a lower bound on a window's distance (its height difference alone) can still beat the best, which is one to three windows for most points. The tube must not touch itself: its radius is less than the helix radius, and less than half the closest distance between the center line's neighboring turns, which is a little less than the pitch. By default the helix runs from (0,-1,0) to (0,1,0) in 4 turns of radius 0.5 starting along x, with a tube radius of 0.1.

Template Parameters
TFloating-point precision.

Constructor & Destructor Documentation

◆ HelixSDF()

template<class T >
EBGeometry::HelixSDF< T >::HelixSDF ( const Vec3T< T > &  a_center1,
const Vec3T< T > &  a_center2,
const T  a_helixRadius,
const T  a_turns,
const T  a_tubeRadius,
const Vec3T< T > &  a_startDirection 
)
inline

Full constructor.

Parameters
[in]a_center1The axis point at the first end.
[in]a_center2The axis point at the second end; it must differ from a_center1.
[in]a_helixRadiusThe distance from the axis to the tube's center line, finite and positive.
[in]a_turnsThe number of turns, finite and positive (not necessarily whole).
[in]a_tubeRadiusThe tube's radius, positive, less than a_helixRadius and than half the closest distance between neighboring turns of the center line.
[in]a_startDirectionDirection from the axis to the center line at the first end. Only its part across the axis is used, and that must not be zero.

Member Function Documentation

◆ centerLine()

template<class T >
Vec3T< T > EBGeometry::HelixSDF< T >::centerLine ( const T  a_angle) const
inlinenoexcept

Get the point on the center line at a helix angle.

Parameters
[in]a_angleThe angle in radians, from 0 at the first end to 2 pi getTurns() at the second.
Returns
The point.

◆ computeBoundingVolume()

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

The shape's axis-aligned bounding box: that of the cylinder the tube fits in.

Returns
The bounding box.

◆ getCenter1()

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

Get the axis point at the first end.

Returns
m_center1.

◆ getCenter2()

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

Get the axis point at the second end.

Returns
m_center2.

◆ getHelixRadius()

template<class T >
const T & EBGeometry::HelixSDF< T >::getHelixRadius ( ) const
inlinenoexcept

Get the helix radius.

Returns
m_helixRadius.

◆ getStartDirection()

template<class T >
const Vec3T< T > & EBGeometry::HelixSDF< T >::getStartDirection ( ) const
inlinenoexcept

Get the unit direction from the axis to the center line at the first end.

Returns
m_start.

◆ getTubeRadius()

template<class T >
const T & EBGeometry::HelixSDF< T >::getTubeRadius ( ) const
inlinenoexcept

Get the tube radius.

Returns
m_tubeRadius.

◆ getTurns()

template<class T >
const T & EBGeometry::HelixSDF< T >::getTurns ( ) const
inlinenoexcept

Get the number of turns.

Returns
m_turns.

◆ operator=() [1/2]

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

Copy assignment.

Returns
Reference to (*this).

◆ operator=() [2/2]

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

Move assignment.

Returns
Reference to (*this).

◆ signedDistance()

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

Signed distance function for the helix.

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

◆ windowMinimum()

template<class T >
T EBGeometry::HelixSDF< T >::windowMinimum ( const T  a_k,
const T  a_rho,
const T  a_phi,
const T  a_y,
const T  a_rate,
const T  a_last 
) const
inlineprotectednoexcept

The smallest squared distance from a point to the center line over one window of helix angles, phi + 2 pi k + s with |s| <= pi, cut to the helix' angles.

f(s) = rho^2 + R^2 - 2 rho R cos(s) + (Y - rate s)^2, with Y the point's height over the line at s = 0. Its derivative is 2 g(s), g(s) = rho R sin(s) + rate^2 s - rate Y, which increases where rho R cos(s) + rate^2 > 0, on (-s_c, s_c), and decreases outside it. A minimum inside the window is therefore where g crosses zero in (-s_c, s_c), at most once; otherwise f is least at an end. Out of line on a device (the helix' solver): inlined, it would be copied into every level of every tape kernel, whatever shapes the tape holds, which makes the device compile of every tape kernel much slower. A call costs little beside the search.

Parameters
[in]a_kThe window, as a whole number.
[in]a_rhoThe point's distance from the axis.
[in]a_phiThe point's angle around the axis, from the start direction.
[in]a_yThe point's height along the axis, from the first end.
[in]a_rateThe rise per radian.
[in]a_lastThe last angle, 2 pi times the turns.
Returns
The squared distance.

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