Core 1.0
Public Member Functions | Static Public Attributes | Friends | List of all members
Capsule Class Reference

A line-swept-sphere. More...

#include <capsule.h>

Inheritance diagram for Capsule:
Cylinder Axis

Public Member Functions

 Capsule ()
 Empty.
 
 Capsule (const Vector &, const Vector &, const double &)
 Creates a capsule. More...
 
 ~Capsule ()
 Empty.
 
bool Inside (const Vector &) const
 Check if a point is inside the capsule. More...
 
double R (const Vector &) const
 Computes the squared distance between a point and the capsule. More...
 
double Signed (const Vector &) const
 Computes the signed distance between a point and the capsule. More...
 
bool Intersect (const Ray &) const
 Check the intersection between a capsule and a ray. More...
 
int Intersect (const Ray &, double &, double &) const
 Compute the intersections between a capsule and a ray. More...
 
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersections between a capsule and a ray. More...
 
int Intersect (const Ray &, double &, Vector &) const
 Compute the first positive intersection between a capsule and a ray. More...
 
double R (const Capsule &, double &, double &) const
 Computes the squared distance between two capsules. More...
 
bool Intersect (const Capsule &, double &, double &) const
 Check if two capsules intersect. More...
 
Capsule Rotated (const Matrix &) const
 Return a capsule rotated by a given matrix. More...
 
Capsule Translated (const Vector &) const
 Return a capsule translated by a given vector. More...
 
Capsule Scaled (const double &) const
 Return a scaled capsule. More...
 
Box GetBox () const
 Computes the tight bounding box of the capsule. More...
 
double Volume () const
 Compute the volume.
 
double Area () const
 Compute the surface area.
 
double Radius () const
 Gets the radius of a cylinder.
 

Static Public Attributes

static const Capsule Unit
 Unit vertical capsule.
 

Friends

std::ostream & operator<< (std::ostream &, const Capsule &)
 Overloaded. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Cylinder
 Cylinder ()
 Empty.
 
 Cylinder (const Vector &, const Vector &, const double &)
 Creates a cylinder. More...
 
 Cylinder (const double &, const double &, const double &=1.0)
 Creates a vertical cylinder. More...
 
 Cylinder (const Box &, const Axis &)
 Creates the boudning cylinder embedding a box rotated around an axis. More...
 
 ~Cylinder ()
 Empty.
 
double Radius () const
 Gets the radius of a cylinder.
 
int Intersect (const Ray &, double &, double &) const
 Compute the intersection between a cylinder and a ray. More...
 
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersections between a cylinder and a ray. More...
 
int Intersect (const Ray &, double &, Vector &) const
 Compute the first positive intersection between a cylinder and a ray. More...
 
bool Intersect (const Ray &) const
 Check the intersection between a cylinder and a ray. More...
 
bool Inside (const Vector &) const
 Check if a point is inside or outside the cylinder. More...
 
double Volume () const
 Computes the volume of a cylinder.
 
double Area () const
 Computes the surface area of a cylinder.
 
void Scale (const double &)
 Uniformly scales a cylinder. More...
 
Cylinder Transformed (const FrameScaled &) const
 Transformed cylinder. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the cylinder. More...
 
Box GetBox () const
 Computes the axis-aligned bounding box of a cylinder. More...
 
Cylinder Rotated (const Matrix &) const
 Return a cylinder rotated by a given matrix. More...
 
Cylinder Translated (const Vector &) const
 Return a cylinder translated by a given vector. More...
 
Cylinder Scaled (const double &) const
 Return a scaled cylinder. More...
 
double R (const Vector &) const
 Squared distance between a point and the cylinder. More...
 
double R (const Vector &, double &) const
 Computes the squared distance between a point and the cylinder. More...
 
double Signed (const Vector &) const
 Signed Euclidean distance between a point and a cylinder. More...
 
Vector Normal (const Vector &) const
 Compute the normal vector to a cylinder skeleton. More...
 
Vector Vertex (int) const
 Return one of the end vertexes of the axis.
 
- Protected Member Functions inherited from Axis
double Radial (const Vector &, Vector &, Vector &) const
 Compute the radial coordinates of a point. More...
 
Vector2 Radial (const Vector &) const
 Compute the radial coordinates of a point. More...
 
 Axis ()
 Empty.
 
 Axis (const Vector &, const Vector &)
 Creates an axis given end vertices. More...
 
 ~Axis ()
 Empty.
 
void Rotate (const Matrix &)
 Rotates an axis. More...
 
void Translate (const Vector &)
 Translates an axis. More...
 
void Scale (const double &)
 Uniformly scales an axis. More...
 
void Scale (const Vector &)
 Scales an axis. More...
 
Quadric Equation (const Ray &) const
 Compute the polynomial equation of the Euclidean distance between a ray and the axis. More...
 
Vector Vertex (int) const
 Return one of the end vertexes of the axis.
 
Vector Point (const double &) const
 Compute a point on the axis.
 
Vector GetAxis () const
 Returns the normalized axis vector.
 
double Length () const
 Return the axis length.
 
Vector Symmetric (const Vector &) const
 Symmetric point. More...
 
Sphere Symmetric (const Sphere &) const
 Symmetric sphere. More...
 
Vector Normal (const Vector &) const
 Compute the normal vector between a point and its projection onto the edge. More...
 
double R (const Vector &) const
 Compute the squared distance to the segment. More...
 
double R (const Axis &) const
 Compute the squared distance between two axes. More...
 
double R (const Vector &, double &) const
 Compute the squared distance to the axis. More...
 
Matrix GetFrame () const
 Compute an orthonormal frame attached to the axis. More...
 
- Static Protected Member Functions inherited from Cylinder
static int Cast (const Vector &, double &, double &)
 Computes the inverse mapping of a point. More...
 
- Static Protected Member Functions inherited from Axis
static Matrix GetFrame (const Vector &)
 Compute an orthonormal frame attached to the axis. More...
 
static Vector BoxVector (const Vector &)
 Compute the box vector extent of a unit circle with a given axis. More...
 
- Protected Attributes inherited from Cylinder
double r = 1.0
 Radius.
 
- Protected Attributes inherited from Axis
Vector b = Vector::Z
 End vertices of the axis.
 
Vector axis = Vector::Z
 Normalized axis vector.
 
double length = 1.0
 Length of the axis.
 
- Static Protected Attributes inherited from Cylinder
static const double epsilon = 1.0e-4
 Epsilon value for intersection tests.
 
static const Cylinder Unit
 Unit vertical cylinder.
 

Detailed Description

A line-swept-sphere.

Capsules, which are line-swept-spheres, make good bounding volumes. The function Intersect(const Capsule&,const Capsule&) implements an efficient algorithm to detect the intersection between two capsules.

Note that capsule-ray intersection member function assumes that the ray direction is normalized.

Constructor & Destructor Documentation

◆ Capsule()

Capsule::Capsule ( const Vector a,
const Vector b,
const double &  r 
)
explicit

Creates a capsule.

Parameters
a,bVertices
rRadius.

Member Function Documentation

◆ GetBox()

Box Capsule::GetBox ( ) const

Computes the tight bounding box of the capsule.

See also
Circle::GetBox()

◆ Inside()

bool Capsule::Inside ( const Vector p) const

Check if a point is inside the capsule.

Parameters
pPoint.

◆ Intersect() [1/5]

bool Capsule::Intersect ( const Capsule cs,
double &  u,
double &  v 
) const

Check if two capsules intersect.

The algorithm computes the squared distance and compares it with the squared sum of radii.

Parameters
csThe other capsule.
u,vThe location of the closests points on the two capsules where minimum distance occurs.
See also
Capsule::R()

◆ Intersect() [2/5]

bool Capsule::Intersect ( const Ray ray) const

Check the intersection between a capsule and a ray.

Note the function assumes that the ray is normalized, i.e. has a unit direction vector.

Intersections are sorted according to intersection depth.

Parameters
rayThe normalized ray.

◆ Intersect() [3/5]

int Capsule::Intersect ( const Ray ray,
double &  ta,
double &  tb 
) const

Compute the intersections between a capsule and a ray.

Note that this member function assumes that the ray is normalized, i.e. has a unit direction vector.

Intersections are sorted according to intersection depth.

Parameters
rayThe normalized ray.
ta,tbIntersection depths.

◆ Intersect() [4/5]

int Capsule::Intersect ( const Ray ray,
double &  ta,
double &  tb,
Vector na,
Vector nb 
) const

Compute the intersections between a capsule and a ray.

Intersections are sorted according to intersection depth.

Note that this function is not fully optimized, as it relies on the member functions Sphere::Intersect() and Cylinder::Intersect() to compute the intersection with the union of two spheres and a cylinder. Several enhancements could be made by inlining the functions with the corresponding code and removing redundant computations.

Parameters
rayThe ray.
ta,tbIntersection depths.
na,nbNormals at intersection points.

◆ Intersect() [5/5]

int Capsule::Intersect ( const Ray ray,
double &  t,
Vector n 
) const

Compute the first positive intersection between a capsule and a ray.

Parameters
rayThe ray.
tIntersection depth.
nNormal at intersection point.

◆ R() [1/2]

double Capsule::R ( const Capsule cs,
double &  u,
double &  v 
) const

Computes the squared distance between two capsules.

Parameters
csThe line-swept-sphere.
u,vThe location of the closests points on the segments of the capsules where minimum distance occurs.

◆ R() [2/2]

double Capsule::R ( const Vector p) const

Computes the squared distance between a point and the capsule.

Parameters
pPoint.

◆ Rotated()

Capsule Capsule::Rotated ( const Matrix r) const

Return a capsule rotated by a given matrix.

Parameters
rRotation matrix.

◆ Scaled()

Capsule Capsule::Scaled ( const double &  s) const

Return a scaled capsule.

Parameters
sScaling factor.

◆ Signed()

double Capsule::Signed ( const Vector p) const

Computes the signed distance between a point and the capsule.

Parameters
pPoint.

◆ Translated()

Capsule Capsule::Translated ( const Vector t) const

Return a capsule translated by a given vector.

Parameters
tTranslation vector.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Capsule c 
)
friend

Overloaded.

Parameters
sStream.
cCapsule.