Core 1.0
Cylinder Class Reference

A cylinder characterized by its end vertices and radius. More...

#include <cylinder.h>

Inheritance diagram for Cylinder:
Axis Capsule

Public Member Functions

 Cylinder ()
 Empty.
 
 Cylinder (const Vector &, const Vector &, const double &)
 Creates a cylinder.
 
 Cylinder (const double &, const double &, const double &=1.0)
 Creates a vertical cylinder.
 
 Cylinder (const Vector &, const double &, const double &=1.0)
 Creates a vertical cylinder.
 
 Cylinder (const Circle &, const double &, bool=false)
 Create a vertical cylinder as an extruded circle.
 
 Cylinder (const Box &, const Axis &)
 Creates the boudning cylinder embedding a box rotated around an axis.
 
 ~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.
 
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersections between a cylinder and a ray.
 
int Intersect (const Ray &, double &, Vector &) const
 Compute the first positive intersection between a cylinder and a ray.
 
bool Intersect (const Ray &) const
 Check the intersection between a cylinder and a ray.
 
bool Inside (const Vector &) const
 Check if a point is inside or outside the cylinder.
 
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.
 
Cylinder Transformed (const FrameScaled &) const
 Transformed cylinder.
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the cylinder.
 
Box GetBox () const
 Computes the axis-aligned bounding box of a cylinder.
 
Cylinder Rotated (const Matrix &) const
 Return a cylinder rotated by a given matrix.
 
Cylinder Translated (const Vector &) const
 Return a cylinder translated by a given vector.
 
Cylinder Scaled (const double &) const
 Return a scaled cylinder.
 
double R (const Vector &) const
 Squared distance between a point and the cylinder.
 
double R (const Vector &, double &) const
 Computes the squared distance between a point and the cylinder.
 
double Signed (const Vector &) const
 Signed Euclidean distance between a point and a cylinder.
 
Vector Normal (const Vector &) const
 Compute the normal vector to a cylinder.
 
Vector SignedNormal (const Vector &) const
 Compute the normal vector to the surface of the cylinder.
 
Vector Vertex (int) const
 Return one of the end vertexes of the axis.
 
- Public Member Functions inherited from Axis
 Axis ()
 Empty.
 
 Axis (const Vector &, const Vector &)
 Creates an axis given end vertices.
 
 ~Axis ()
 Empty.
 
void Rotate (const Matrix &)
 Rotates an axis.
 
void Translate (const Vector &)
 Translates an axis.
 
void Scale (const double &)
 Uniformly scales an axis.
 
void Scale (const Vector &)
 Scales an axis.
 
Quadric Equation (const Ray &) const
 Compute the polynomial equation of the Euclidean distance between a ray and the axis.
 
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.
 
Sphere Symmetric (const Sphere &) const
 Symmetric sphere.
 
Vector Normal (const Vector &) const
 Compute the normal vector between a point and its projection onto the edge.
 
double R (const Vector &) const
 Compute the squared distance to the segment.
 
double R (const Axis &) const
 Compute the squared distance between two axes.
 
double R (const Vector &, double &) const
 Compute the squared distance to the axis.
 
Matrix GetFrame () const
 Compute an orthonormal frame attached to the axis.
 
Vector2 Radial (const Vector &) const
 Compute the radial coordinates of a point.
 

Static Public Member Functions

static Vector2 Cast (const Vector &)
 Computes the inverse mapping of a point.
 
- Static Public Member Functions inherited from Axis
static Matrix GetFrame (const Vector &)
 Compute an orthonormal frame attached to the axis.
 
static Vector BoxVector (const Vector &)
 Compute the box vector extent of a unit circle with a given axis.
 

Static Public Attributes

static const double epsilon = 1.0e-4
 Epsilon value for intersection tests.
 
static const Cylinder Unit
 Unit vertical cylinder.
 
- Static Public Attributes inherited from Axis
static const Axis Z
 Axes from origin, identical to Axis(Vector::Null,Vector::X) ...
 

Protected Attributes

double r = 1.0
 Radius.
 
- Protected Attributes inherited from Axis
Vector b = Vector::Z
 End vertexes of the axis.
 
Vector axis = Vector::Z
 Normalized axis vector.
 
double length = 1.0
 Length of the axis.
 

Friends

std::ostream & operator<< (std::ostream &s, const Cylinder &cylinder)
 Overloaded.
 

Additional Inherited Members

- Protected Member Functions inherited from Axis
double Radial (const Vector &, Vector &, Vector &) const
 Compute the radial coordinates of a point.
 

Detailed Description

A cylinder characterized by its end vertices and radius.

Note that only the radius is stored, the squared radius value is computed on the fly whenever needed.

Constructor & Destructor Documentation

◆ Cylinder() [1/5]

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

Creates a cylinder.

Parameters
a,bEnd vertices of the axis.
rRadius of the cylinder.

◆ Cylinder() [2/5]

Cylinder::Cylinder ( const double & a,
const double & b,
const double & r = 1.0 )
explicit

Creates a vertical cylinder.

Parameters
a,bHeight of apexes.
rRadius.

◆ Cylinder() [3/5]

Cylinder::Cylinder ( const Vector & c,
const double & h,
const double & r = 1.0 )
explicit

Creates a vertical cylinder.

Parameters
cBase center vertex.
hHeight.
rRadius.

Same as:

Cylinder cylinder(c, c + Vector(0.0, 0.0, h), r);
Cylinder()
Empty.
Definition cylinder.h:16
double r
Radius.
Definition cylinder.h:13
Vectors in three dimensions.
Definition evector.h:20

◆ Cylinder() [4/5]

Cylinder::Cylinder ( const Circle & c,
const double & h,
bool symmetric = false )
explicit

Create a vertical cylinder as an extruded circle.

Parameters
cCircle.
hHeight.
symmetricExtrude in both directions, set to false by default.

Same as:

double h;
Cylinder cylinder(c.Center(), c.Center() + c.Axis() * h, c.Radius());
Circles.
Definition circle.h:11
Vector Center() const
Gets the center of a circle.
Definition circle.h:56
Vector Axis() const
Axis of the circle.
Definition circle.h:68
double Radius() const
Radius of the circle.
Definition circle.h:62

◆ Cylinder() [5/5]

Cylinder::Cylinder ( const Box & box,
const Axis & ax )
explicit

Creates the boudning cylinder embedding a box rotated around an axis.

Parameters
boxThe box.
axThe axis.

Member Function Documentation

◆ Cast()

Vector2 Cylinder::Cast ( const Vector & p)
static

Computes the inverse mapping of a point.

Projects the point onto the z-axis unit cylinder, uv-coordinates are set to unit interval [0,1].

Parameters
pPoint.
Returns
Inverse mapping coordinates.

◆ GetBox()

Box Cylinder::GetBox ( ) const

Computes the axis-aligned bounding box of a cylinder.

See also
Circle::GetBox()

◆ Inside()

bool Cylinder::Inside ( const Vector & p) const

Check if a point is inside or outside the cylinder.

Parameters
pPoint.

◆ Intersect() [1/4]

bool Cylinder::Intersect ( const Ray & ray) const

Check the intersection between a cylinder and a ray.

Parameters
rayThe ray.

◆ Intersect() [2/4]

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

Compute the intersection between a cylinder and a ray.

Intersections are sorted according to intersection depth.

Parameters
rayThe ray.
ta,tbIntersection depths.

◆ Intersect() [3/4]

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

Compute the intersections between a cylinder and a ray.

Intersections are sorted according to intersection depth.

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

◆ Intersect() [4/4]

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

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

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

◆ Normal()

Vector Cylinder::Normal ( const Vector & p) const

Compute the normal vector to a cylinder.

Project the point in space onto the axis of the cylinder. If projection lies inside the segment, then return the normal to the segment minus the right radius direction, otherwise perform computations for the end caps.

Return Vector::Null if the point is inside the cylinder.

Parameters
pPoint.

◆ R() [1/2]

double Cylinder::R ( const Vector & p) const

Squared distance between a point and the cylinder.

From A. Barbier and E. Galin. Fast distance Computation between a Point and Cylinders, Cones, Line-swept-Spheres and Cone-Spheres. Journal of Graphics Tools, 9(2), 11-19, 2004.

Cost in worst case: 11 +, 9 *, 1 sqrt, 3 if.

Parameters
pPoint.
double Cylinder::R(const Vector& p) const
{
Vector n = p - a; // Cost: 3+
double s = axis*n; // Cost: 3* 2+
double ra = n*n; // Cost: 3* 2+
// Vertex A
if (s < 0.0)
{
double z = s*s; // Cost: 1*
double u = ra - z; // Cost: 1+
// Inside disc at vertex A
if (u < r*r) // Cost: 1?
{
return z;
}
// Circle A
else
{
u = sqrt(u); // Cost: 1 sqrt
u -= r; // Cost: 1+
return z + u*u; // Cost: 1* 1+
}
}
else
{
// Vertex B
if (s > length)
{
double z = s - length; // 1+
z *= z; // 1*
double u = ra - s*s; // 1+ 1*
// Inside disc at vertex B
if (u < r*r)
{
return z;
}
// Circle A
else
{
u = sqrt(u); // 1 sqrt
u -= r; // 1+
return z + u*u; // 1* 1+
}
}
// Cylinder
else
{
double z = s*s; // 1*
double u = ra - z; // 1+
if (u < r*r)
{
return 0;
}
else
{
u = sqrt(u); // 1 sqrt
u -= r; // 1+
return u*u; // 1*
}
}
}
}
Vector axis
Normalized axis vector.
Definition axis.h:17
double length
Length of the axis.
Definition axis.h:18
double R(const Vector &) const
Squared distance between a point and the cylinder.
Definition cylinder.cpp:188

◆ R() [2/2]

double Cylinder::R ( const Vector & p,
double & s ) const

Computes the squared distance between a point and the cylinder.

Parameters
pPoint.
sReturned position of the projected point onto the axis of the cylinder.
See also
Cylinder::R(const Vector&);

◆ RandomInside()

Vector Cylinder::RandomInside ( Random & random = Random::R239) const

Generate a random vector inside the cylinder.

Parameters
randomRandom number generator.

◆ Rotated()

Cylinder Cylinder::Rotated ( const Matrix & r) const

Return a cylinder rotated by a given matrix.

Parameters
rRotation matrix.

◆ Scale()

void Cylinder::Scale ( const double & s)

Uniformly scales a cylinder.

Parameters
sScaling factor.

◆ Scaled()

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

Return a scaled cylinder.

Parameters
sScaling factor.

◆ Signed()

double Cylinder::Signed ( const Vector & p) const

Signed Euclidean distance between a point and a cylinder.

Parameters
pPoint.

◆ SignedNormal()

Vector Cylinder::SignedNormal ( const Vector & p) const

Compute the normal vector to the surface of the cylinder.

Parameters
pPoint.

◆ Transformed()

Cylinder Cylinder::Transformed ( const FrameScaled & frame) const

Transformed cylinder.

Parameters
frameFrame.

◆ Translated()

Cylinder Cylinder::Translated ( const Vector & t) const

Return a cylinder translated by a given vector.

Parameters
tTranslation vector.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Cylinder & cylinder )
friend

Overloaded.

Parameters
sStream.
cylinderThe cylinder.