geomc 1.0
A c++ linear algebra template library
Loading...
Searching...
No Matches
Shape

Shape-related functions and classes. More...

Topics

 Spline
 Splines and curves.
 

Concepts

concept  geom::BoundedObject
 A shape which can efficiently report its bounding box.
 
concept  geom::ConvexObject
 A convex shape which implements its convex support function.
 
concept  geom::RayIntersectableObject
 A shape which can be intersected by a ray.
 
concept  geom::RegionObject
 A shape which can test for point containment.
 
concept  geom::SdfObject
 A shape which can report its exact signed distance field.
 
concept  geom::InteriorMeasurableObject
 A shape which can measure its interior region.
 
concept  geom::BoundaryMeasurableObject
 A shape which can measure its boundary.
 
concept  geom::MeasurableObject
 A shape which can measure both its surface area and volume.
 
concept  geom::ProjectableObject
 A shape which can perform an orthogonal projection to its boundary.
 

Classes

class  AnyConvex< T, N >
 Helper class which virtualizes the static polymorphism of Convex shapes. More...
 
class  AnyConvexImpl< Shape >
 Implementation of AnyConvex for a specific Shape. More...
 
class  Bounded< T, N, Derived >
 Base class describing shapes with finite extents in N dimensions. More...
 
class  Capsule< T, N >
 An N-dimensional capsule shape. More...
 
class  Convex< T, N, Derived >
 Base class describing convex shapes in N-dimensional space. More...
 
class  Cylinder< T, N >
 An N-dimensional cylinder, given by its radius and endpoints. More...
 
class  Dilated< Shape >
 A wrapper shape which dilates the extents of another Shape. More...
 
class  Extruded< Shape >
 An axis-aligned extrusion of an arbitrary N-1 dimensional Convex shape. More...
 
class  Frustum< Shape >
 An N-dimensional frustum (truncated pyramid) with an arbitrary Convex shape as its base, and its (possibly excluded) point at the origin. More...
 
class  GridIterator< T, N, Order >
 Iterator over the integer points in an N-dimensional grid. More...
 
class  Hollow< Shape >
 Selects the boundary of a shape. More...
 
class  KDTree< T, N, Object, NodeData >
 A hierarchical spatial index. More...
 
class  Plane< T, N >
 A geometric plane or hyperplane. More...
 
class  Projectable< T, N, Derived >
 Base class describing N-dimensional shapes which implement the ability to project an arbitrary point to the nearest point on their surface. More...
 
class  RayIntersectable< T, N, Derived >
 Base class describing N-dimensional shapes which can be intersection-tested with a Ray. More...
 
class  Rect< T, N >
 An N-dimensional axis-aligned interval. More...
 
class  SdfEvaluable< T, N, Derived >
 Base class describing N-dimensional shapes which implement a signed distance function. More...
 
class  Similar< Shape >
 A shape transformed by a similarity transform (translation, rotation, and scale). More...
 
class  Simplex< T, N >
 A simplex in N dimensions (e.g. a tetrahedron, triangle, line, point). More...
 
class  Sphere< T, N >
 An N-dimensional circle, sphere, or hypersphere with a filled interior. More...
 
class  SphericalCap< T, N >
 The surface of a sphere within a certain angle from its pole. More...
 
class  Transformed< Shape >
 A wrapper shape which transforms another arbitrary shape with an AffineTransform. More...
 
class  Transformed< Rect< T, N > >
 Partial specialization of Transformed for Rects.
 

Macros

#define MAX_KDTREE_ARITY   16
 

Typedefs

template<typename T, index_t N>
using AffineBox = Transformed<Rect<T,N>>
 Convenience typedef for transformed Rects.
 
template<typename T, index_t N>
using Box = Similar<Rect<T,N>>
 Convenience typedef for arbitrarily-oriented Rects.
 
template<typename T>
using Circle = Sphere<T,2>
 A 2D circle.
 
template<typename T>
using Cone = Frustum<Circle<T>>
 Convenience typedef for a 3D cone with its tip at the origin.
 
template<typename T, index_t N>
using SphericalShell = Dilated<Hollow<Sphere<T,N>>>
 Convenience typedef for a spherical shell.
 
typedef Shape::elem_t T
 
template<typename T>
using Tetrahedron = Simplex<T,3>
 
template<typename T>
using TransformedCone = Transformed<Cone<T>>
 Convenience typedef for an oriented cone.
 
template<typename T>
using Triangle = Simplex<T,2>
 
template<typename T, index_t N>
using ViewFrustum = Transformed< Frustum< Rect<T,N-1> > >
 Convenience typedef for oriented, rectangular, N-dimensional Frustums.
 

Enumerations

enum  ArrayOrder { ARRAYORDER_FIRST_DIM_CONSECUTIVE , ARRAYORDER_LAST_DIM_CONSECUTIVE }
 Array traversal order, specified in terms of which axes to increment first. More...
 
enum class  KDAxisChoice { AXIS_LONGEST , AXIS_HIGHEST_VARIANCE , AXIS_CYCLICAL }
 Strategy for choosing an axis along which to split a group of objects in a spatial index. More...
 
enum class  KDInsertionChoice { INSERT_SMALLEST_VOLUME_INCREASE , INSERT_SHORTEST_DISTANCE }
 Strategy for insertion of an object into an existing tree. More...
 
enum class  KDPivotChoice { PIVOT_MEAN , PIVOT_MEDIAN }
 Strategy for choosing the pivot value when splitting a group of objects in a spatial index. More...
 

Functions

 AnyConvexImpl (const Shape &&s)
 
 AnyConvexImpl (const Shape &s)
 
virtual Rect< T, N_impl_bounds () const =0
 
virtual Rect< T, N > _impl_bounds () const
 
virtual point_t _impl_convex_support (Vec< T, N > p) const =0
 
virtual point_t _impl_convex_support (Vec< T, N > p) const
 
template<typename Shape>
AnyConvexImpl< Shape > as_any_convex (const Shape &s)
 Wrap s in a virtual class which implements the Convex concept.
 
Rect< T, Nbounds () const
 
Rect< T, Nbounds () const
 Produces an axis-aligned box completely enclosing this shape.
 
Rect< T, Nbounds () const
 Produces an axis-aligned box completely enclosing this shape.
 
Vec< T, N > clip (Vec< T, N > p) const
 Nearest point on the interior of the shape.
 
bool contains (Vec< T, N > p) const
 Shape-point overlap test.
 
point_t convex_support (point_t d) const
 
point_t convex_support (point_t d) const
 Geometric convex support function.
 
template<typename Shape>
Dilated< Shape > dilate (const Dilated< Shape > &s, typename Shape::elem_t dilation)
 Dilate the shape s by the amount dilation.
 
template<typename Shape>
Dilated< Shape > dilate (const Shape &s, typename Shape::elem_t dilation)
 Dilate the shape s by the amount dilation.
 
template<typename T, index_t N>
Sphere< T, Ndilate (const Sphere< T, N > &s, T dilation)
 Dilate the Sphere s by the amount dilation.
 
template<typename T, index_t N>
Plane< T, Ndilate (Plane< T, N > p, T dilation)
 Dilate the Plane p by the amount dilation.
 
template<typename Shape>
Extruded< Shape > extrude (const Shape &s, typename Shape::elem_t h0, typename Shape::elem_t h1)
 Convenience function to extrude the shape s between heights h0 and h1 by wrapping s in the Extruded template.
 
template<typename Shape>
Frustum< Shape > frustum (const Shape &s, typename Shape::elem_t h0, typename Shape::elem_t h1)
 Convenience function to raise the shape s into a frustum between heights h0 and h1, by wrapping s in the Frustum template.
 
Rect< T, 1 > intersect (const Ray< T, N > &r) const
 Ray/shape intersection.
 
template<typename Shape>
bool intersects (const Convex< T, N, Shape > &other) const
 Convex shape overlap test.
 
template<typename T, index_t N>
bool intersects (const AnyConvex< T, N > &shape_a, const AnyConvex< T, N > &shape_b)
 
Vec< T, N > normal (Vec< T, N > p) const
 Unit-length outward-facing direction.
 
template<typename T, index_t N>
Capsule< T, Noperator* (const Isometry< T, N > &xf, const Capsule< T, N > &c)
 Transform a capsule by an isometry.
 
template<typename T, index_t N>
Cylinder< T, Noperator* (const Isometry< T, N > &xf, const Cylinder< T, N > &c)
 Transform a cylinder by an isometry.
 
template<typename T, index_t N, typename Shape>
Dilated< Shape > operator* (const Isometry< T, N > &xf, const Dilated< Shape > &s)
 Transform a dilated shape by an isometry.
 
template<typename T, index_t N>
Simplex< T, Noperator* (const Isometry< T, N > &xf, const Simplex< T, N > &s)
 Transform a simplex by an isometry.
 
template<typename T, index_t N>
Sphere< T, Noperator* (const Isometry< T, N > &xf, const Sphere< T, N > &s)
 Transform a sphere by an isometry.
 
template<typename Shape>
Similar< Shape > operator* (const Similarity< typename Shape::elem_t, Shape::N > &xf, const Shape &shape)
 Transform the shape shape by wrapping it with a Similarity transform.
 
template<typename Shape>
Similar< Shape > operator* (const Similarity< typename Shape::elem_t, Shape::N > &xf, const Similar< Shape > &s)
 Transform the shape s by xf.
 
template<typename T, index_t N>
Capsule< T, Noperator* (const Similarity< T, N > &xf, const Capsule< T, N > &c)
 Transform a capsule by a similarity transform.
 
template<typename T, index_t N>
Cylinder< T, Noperator* (const Similarity< T, N > &xf, const Cylinder< T, N > &c)
 Transform a cylinder by a similarity transform.
 
template<typename T, index_t N, typename Shape>
Dilated< Shape > operator* (const Similarity< T, N > &xf, const Dilated< Shape > &s)
 Transform a dilated shape by a similarity transform.
 
template<typename T, index_t N>
Simplex< T, Noperator* (const Similarity< T, N > &xf, const Simplex< T, N > &s)
 Transform a simplex by a similarity transform.
 
template<typename T, index_t N>
Sphere< T, Noperator* (const Similarity< T, N > &xf, const Sphere< T, N > &s)
 Transform a sphere by a similarity transform.
 
template<typename Shape>
Transformed< Shape > operator* (const AffineTransform< typename Shape::elem_t, Shape::N > &xf, const Shape &s)
 Transform the shape s by wrapping it in an Transformed class.
 
template<typename Shape>
Transformed< Shape > operator* (const AffineTransform< typename Shape::elem_t, Shape::N > &xf, const Transformed< Shape > &s)
 Transform the transformed shape s by xf.
 
template<typename Shape, typename T, index_t N>
Transformed< Shape > operator* (const Isometry< T, N > &xf, const Transformed< Shape > &s)
 Transform the shape s by an isometry xf.
 
template<typename Shape, typename T, index_t N>
Transformed< Shape > operator* (const Similarity< T, N > &xf, const Transformed< Shape > &s)
 Transform the shape s by a similarity transform xf.
 
template<typename Shape>
Similar< Shape > & operator*= (Similar< Shape > &s, const Similarity< typename Shape::elem_t, Shape::N > &xf)
 In-place transform the shape s by xf.
 
template<typename Shape>
Transformed< Shape > & operator*= (Transformed< Shape > &s, const AffineTransform< typename Shape::elem_t, Shape::N > &xf)
 In-place transform the transformed shape s by xf.
 
template<typename T, index_t N>
Capsule< T, Noperator/ (const Capsule< T, N > &c, const Isometry< T, N > &xf)
 Inverse-transform a capsule by an isometry.
 
template<typename T, index_t N>
Cylinder< T, Noperator/ (const Cylinder< T, N > &c, const Isometry< T, N > &xf)
 Inverse-transform a cylinder by an isometry.
 
template<typename T, index_t N, typename Shape>
Dilated< Shape > operator/ (const Dilated< Shape > &s, const Isometry< T, N > &xf)
 Inverse-transform a dilated shape by an isometry.
 
template<typename T, index_t N>
Simplex< T, Noperator/ (const Simplex< T, N > &s, const Isometry< T, N > &xf)
 Inverse-transform a simplex by an isometry.
 
template<typename T, index_t N>
Sphere< T, Noperator/ (const Sphere< T, N > &s, const Isometry< T, N > &xf)
 Inverse-transform a sphere by an isometry.
 
template<typename Shape>
Similar< Shape > operator/ (const Shape &s, const Similarity< typename Shape::elem_t, Shape::N > &xf)
 Transform the shape s by the inverse of xf.
 
template<typename Shape>
Similar< Shape > operator/ (const Similar< Shape > &s, const Similarity< typename Shape::elem_t, Shape::N > &xf)
 Transform the shape s by the inverse of xf.
 
template<typename T, index_t N>
Capsule< T, Noperator/ (const Capsule< T, N > &c, const Similarity< T, N > &xf)
 Inverse-transform a capsule by a similarity transform.
 
template<typename T, index_t N>
Cylinder< T, Noperator/ (const Cylinder< T, N > &c, const Similarity< T, N > &xf)
 Inverse-transform a cylinder by a similarity transform.
 
template<typename T, index_t N, typename Shape>
Dilated< Shape > operator/ (const Dilated< Shape > &s, const Similarity< T, N > &xf)
 Inverse-transform a dilated shape by a similarity transform.
 
template<typename T, index_t N>
Simplex< T, Noperator/ (const Simplex< T, N > &s, const Similarity< T, N > &xf)
 Inverse-transform a simplex by a similarity transform.
 
template<typename T, index_t N>
Sphere< T, Noperator/ (const Sphere< T, N > &s, const Similarity< T, N > &xf)
 Inverse-transform a sphere by a similarity transform.
 
template<typename Shape>
Transformed< Shape > operator/ (const Shape &s, const AffineTransform< typename Shape::elem_t, Shape::N > &xf)
 Transform the shape s by the inverse of xf.
 
template<typename Shape>
Transformed< Shape > operator/ (const Transformed< Shape > &s, const AffineTransform< typename Shape::elem_t, Shape::N > &xf)
 Transform the transformed shape s by the inverse of xf.
 
template<typename Shape, typename T, index_t N>
Transformed< Shape > operator/ (const Transformed< Shape > &s, const Isometry< T, N > &xf)
 Inverse transform the shape s by an isometry xf.
 
template<typename Shape, typename T, index_t N>
Transformed< Shape > operator/ (const Transformed< Shape > &s, const Similarity< T, N > &xf)
 Inverse transform the shape s by a similarity transform xf.
 
template<typename Shape>
Similar< Shape > & operator/= (Similar< Shape > &s, const Similarity< typename Shape::elem_t, Shape::N > &xf)
 In-place transform the shape s by the inverse of xf.
 
template<typename Shape>
Transformed< Shape > & operator/= (Transformed< Shape > &s, const AffineTransform< typename Shape::elem_t, Shape::N > &xf)
 In-place transform the transformed shape s by the inverse of xf.
 
Vec< T, N > project (Vec< T, N > p) const
 Nearest point on the surface of the shape.
 
template<typename T, index_t N>
Dilated< Rect< T, N > > roundrect (const Rect< T, N > &rect, T radius)
 Produce a rounded rectangle with corner radius radius.
 
sdf (Vec< T, N > p) const
 
sdf (Vec< T, N > p) const
 Signed distance function.
 
template<typename T, index_t N>
Dilated< Hollow< Sphere< T, N > > > shell (const Sphere< T, N > &s, T thickness)
 Create a spherical shell with wall thickness thickness around the Sphere s.
 
template<typename T, index_t N>
Dilated< Hollow< Sphere< T, N > > > shell (Vec< T, N > center, T r0, T r1)
 Create a spherical shell around center, with inner and outer radii r0 and r1.
 
template<typename T, index_t N>
bool trace_simplex (const Vec< T, N > verts[N], const Ray< T, N > &ray, Vec< T, N-1 > *uv, T *s)
 

Variables

static constexpr index_t N = Shape::N
 
Shape shape
 
template<typename Shape, Transform< typename Shape::elem_t, Shape::N > Xf>
Hollow< Shape > operator* (const Xf &xf, const Hollow< Shape > &s)
 Transform a hollow shape.
 
template<typename Shape, Transform< typename Shape::elem_t, Shape::N > Xf>
Hollow< Shape > operator/ (const Hollow< Shape > &s, const Xf &xf)
 Inverse transform a hollow shape.
 
template<typename Shape, Transform< typename Shape::elem_t, Shape::N > Xf>
Hollow< Shape > & operator*= (Hollow< Shape > &s, const Xf &xf)
 In-place transform a hollow shape.
 
template<typename Shape, Transform< typename Shape::elem_t, Shape::N > Xf>
Hollow< Shape > & operator/= (Hollow< Shape > &s, const Xf &xf)
 In-place inverse transform a hollow shape.
 

Detailed Description

Shape-related functions and classes.

Typedef Documentation

◆ Circle

template<typename T, index_t N>
template<typename T>
using Circle = Sphere<T,2>
related

A 2D circle.

Template Parameters
TCoordinate type

◆ Cone

template<typename Shape>
template<typename T>
using Cone = Frustum<Circle<T>>
related

Convenience typedef for a 3D cone with its tip at the origin.

Formed from a frustum with a circular base.

Template Parameters
TCoordinate type

◆ TransformedCone

template<typename Shape>
template<typename T>
using TransformedCone = Transformed<Cone<T>>
related

Convenience typedef for an oriented cone.

Template Parameters
TCoordinate type

Enumeration Type Documentation

◆ ArrayOrder

enum ArrayOrder

Array traversal order, specified in terms of which axes to increment first.

Enumerator
ARRAYORDER_FIRST_DIM_CONSECUTIVE 

Array traversal by incrementing the first coordinate in the innermost loop.

For matrices, whose coordinates are ordered (row, col), this represens column-major (i.e. "fortran") order. If coordinates are (x, y, ...), then this is row-major order.

ARRAYORDER_LAST_DIM_CONSECUTIVE 

Array traversal by incrementing the last coordinate in the innermost loop.

For matrices, whose coordinates are ordered (row, col), this represents row-major (i.e. "C") order. If coordinates are (x, y, ...), then this is column-major order.

◆ KDAxisChoice

enum class KDAxisChoice
strong

Strategy for choosing an axis along which to split a group of objects in a spatial index.

Enumerator
AXIS_LONGEST 

Divide a node along its longest axis.

AXIS_HIGHEST_VARIANCE 

Divide a node along the axis with the highest position variance.

AXIS_CYCLICAL 

Divide each node along an axis that cycles with tree depth, starting with the x (first) axis at the root node.

◆ KDInsertionChoice

enum class KDInsertionChoice
strong

Strategy for insertion of an object into an existing tree.

Enumerator
INSERT_SMALLEST_VOLUME_INCREASE 

Insert objects into the node that will experience the smallest volume increase as a result of the addition.

INSERT_SHORTEST_DISTANCE 

Insert objects into the node which is closest.

◆ KDPivotChoice

enum class KDPivotChoice
strong

Strategy for choosing the pivot value when splitting a group of objects in a spatial index.

Enumerator
PIVOT_MEAN 

Split a node at the population average.

PIVOT_MEDIAN 

Split a node at the population median.

Function Documentation

◆ _impl_bounds()

template<typename Shape>
virtual Rect< T, N > _impl_bounds ( ) const
inlineprotectedvirtual

◆ _impl_convex_support()

template<typename Shape>
virtual point_t _impl_convex_support ( Vec< T, N > p) const
inlineprotectedvirtual

◆ bounds()

template<typename T, index_t N, typename Derived>
Rect< T, N > bounds ( ) const
inline

Produces an axis-aligned box completely enclosing this shape.

The default implementation calls convex_support() along each of the principal axes to find the extents.

◆ clip()

template<typename T, index_t N, typename Derived>
Vec< T, N > clip ( Vec< T, N > p) const
inline

Nearest point on the interior of the shape.

If p is on the interior of the shape, return p unaltered; otherwise orthogonally project p to the shape's surface.

◆ contains()

template<typename T, index_t N, typename Derived>
bool contains ( Vec< T, N > p) const
inline

Shape-point overlap test.

Return true if the point p is on the surface or interior of the shape, false otherwise.

◆ convex_support()

template<typename T, index_t N, typename Derived>
point_t convex_support ( point_t d) const
inline

Geometric convex support function.

Returns the point on the surface of this convex shape that is furthest along direction d (i.e., has the highest dot product with d).

All shapes which implement this function automatically support geometrical intersection tests with any other Convex object.

Parameters
dDirection along which to find a support plane.
Returns
A point on the surface of this convex shape.

◆ dilate() [1/2]

template<typename T, index_t N>
Sphere< T, N > dilate ( const Sphere< T, N > & s,
T dilation )
related

Dilate the Sphere s by the amount dilation.

(This just adds the amount dilation to the Sphere's radius).

◆ dilate() [2/2]

template<typename T, index_t N>
Plane< T, N > dilate ( Plane< T, N > p,
T dilation )
related

Dilate the Plane p by the amount dilation.

(This just moves the plane dilation units along its normal).

◆ intersect()

template<typename T, index_t N, typename Derived>
Rect< T, 1 > intersect ( const Ray< T, N > & r) const
inline

Ray/shape intersection.

Return the possibly-empty range of ray parameters s such that the Ray overlaps the shape at r.origin + s * r.direction.

For non-convex objects with multiple regions of overlap, this method should return the interval containing the smallest positive value.

◆ intersects()

template<typename T, index_t N, typename Derived>
template<typename Shape>
bool intersects ( const Convex< T, N, Shape > & other) const
inline

Convex shape overlap test.

Returns
True if and only if this convex shape overlaps other; false otherwise.

◆ normal()

template<typename T, index_t N, typename Derived>
Vec< T, N > normal ( Vec< T, N > p) const
inline

Unit-length outward-facing direction.

For any point, return the direction which points directly away from the nearest point on the shape, away from its interior.

This should be the same as the gradient of the sdf().

◆ project()

template<typename T, index_t N, typename Derived>
Vec< T, N > project ( Vec< T, N > p) const
inline

Nearest point on the surface of the shape.

Compute the point on the boundary of the shape which is closest to p.

◆ roundrect()

template<typename T, index_t N>
Dilated< Rect< T, N > > roundrect ( const Rect< T, N > & rect,
T radius )
inline

Produce a rounded rectangle with corner radius radius.

The rounded rectangle will have the extents of rect, but with corners rounded by radius. The radius will be clamped to the maximum possible value that will not cause the corners to overlap.

◆ sdf()

template<typename T, index_t N, typename Derived>
T sdf ( Vec< T, N > p) const
inline

Signed distance function.

Compute a signed distance to the nearest surface point on the shape. Points on the exterior have positive value; points on the interior have negative value; surface points have sdf value 0.

◆ shell() [1/2]

template<typename T, index_t N>
Dilated< Hollow< Sphere< T, N > > > shell ( const Sphere< T, N > & s,
T thickness )
related

Create a spherical shell with wall thickness thickness around the Sphere s.

The wall will be centered on the Sphere's surface.

◆ shell() [2/2]

template<typename T, index_t N>
Dilated< Hollow< Sphere< T, N > > > shell ( Vec< T, N > center,
T r0,
T r1 )
related

Create a spherical shell around center, with inner and outer radii r0 and r1.

It is not required that r0 < r1; the shell will always be constructed with positive thickness.

◆ trace_simplex()

template<typename T, index_t N>
bool trace_simplex ( const Vec< T, N > verts[N],
const Ray< T, N > & ray,
Vec< T, N-1 > * uv,
T * s )
inline

Ray trace an N-1 dimensional simplex (e.g. triangle in 3D, tetrahedron in 4D, a line in 2D etc.), returning the surface parameters of the hit point, given in coordinates of the basis spanned by the edges radiating from verts[0].

Parameters
vertsAn array of the simplex's N vertices.
rayThe ray to intersect with the simplex.
uvBuffer for the surface coordinates of the hitpoint. (return variable; may be null).
sThe ray parameter of the hit point. (return variable)
Returns
true if the ray hit the simplex.