Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
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. 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.
 
- Public Member Functions inherited from Axis
 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 Public Member Functions

static int Cast (const Vector &, double &, double &)
 Computes the inverse mapping of a point. More...
 
- Static Public 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...
 

Static Public Attributes

static const double epsilon = 1.0e-4
 Epsilon value for intersection tests.
 
static const Cylinder Unit
 Unit vertical cylinder.
 

Protected Attributes

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.
 

Friends

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

Additional Inherited Members

- 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...
 

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/3]

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/3]

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/3]

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()

int Cylinder::Cast ( const Vector p,
double &  u,
double &  v 
)
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
u,vinverse 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 skeleton.

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.

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:19
double length
Length of the axis.
Definition: axis.h:20
double r
Radius.
Definition: cylinder.h:13
double R(const Vector &) const
Squared distance between a point and the cylinder.
Definition: cylinder.cpp:155
Vectors in three dimensions.
Definition: evector.h:21

◆ 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.

◆ 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 Function Documentation

◆ operator<<

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

Overloaded.

Parameters
sStream.
cylinderThe cylinder.