Core 1.0
Cone Class Reference

Cones defined as truncated cones. More...

#include <cone.h>

Inheritance diagram for Cone:
Axis ConeTube

Public Member Functions

 Cone ()
 Empty.
 Cone (const Vector &, const Vector &, const double &, const double &=0.0)
 Creates a cone characterized by its end-vertices and radii.
 Cone (const double &, const double &, const double &)
 Creates a vertical cone characterized height and radii.
 ~Cone ()
 Empty.
constexpr double Radius (int) const
 Gets either end-radius of the cone.
int Intersect (const Ray &, double &, double &) const
 Compute the intersections between the cone and a ray.
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersections between the cone and a ray.
int Intersect (const Ray &, double &, Vector &) const
 Compute the first positive intersection between the cone and a ray.
bool Inside (const Vector &) const
 Check if a point is inside or outside the cone.
double R (const Vector &) const
 Compute the distance between a point and the cone.
double Signed (const Vector &) const
 Compute the signed distance between a point and the cone.
Vector Normal (const Vector &) const
 Computes the vector distance between the cone and a point.
void Rotate (const Matrix &)
 Rotates the cone.
void Translate (const Vector &)
 Translates the cone.
void Scale (const double &)
 Uniformly scales the cone.
double Area () const
 Compute the total surface area of the cone.
double Volume () const
 Compute the volume of the cone.
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the cone.
Box GetBox () const
 Compute the axis-aligned bounding box of the cone.
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 bool Clip (const Quadric &, const double &, const double &, double &, double &, bool &, bool &)
 Compute the part of a ray which is inside a truncated cone, given the quadric of the infinite cone.
static bool RayRange (const Ray &, const Vector &, const Vector &, const double &, const double &, const double &, double &, double &, bool &, bool &)
 Compute the depths of the intersection of a ray with a truncated cone.
static Vector SideNormal (const Vector &, const Vector &, const double &)
 Compute the outward normal of the lateral surface of a cone.
static Vector RandomDirection (const Vector &, const double &, Random &=Random::R239)
 Generate a random direction.
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.
static const Cone Unit
 Unit vertical cone.
Static Public Attributes inherited from Axis
static const Axis Z
 Axes from origin, identical to Axis(Vector::Null,Vector::X) ...

Protected Attributes

double rb = 0.0
 Radius of the cone at the first and second vertexes of the axis.
double rlength = -1.0
 Internal parameter.
double conelength = Math::Sqrt2
 Side length of the cone.
Vector2 side = Vector2(-1.0, 1.0) / Math::Sqrt2
 Vector representing the side.
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 Cone &cone)
 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

Cones defined as truncated cones.

Constructor & Destructor Documentation

◆ Cone() [1/2]

Cone::Cone ( const Vector & a,
const Vector & b,
const double & ra,
const double & rb = 0.0 )
explicit

Creates a cone characterized by its end-vertices and radii.

Parameters
a,bEnd vertices of the axis.
ra,rbRadii.

◆ Cone() [2/2]

Cone::Cone ( const double & ab,
const double & ra,
const double & rb )
explicit

Creates a vertical cone characterized height and radii.

Parameters
abHeight.
ra,rbRadii.

Member Function Documentation

◆ Area()

double Cone::Area ( ) const

Compute the total surface area of the cone.

The total surface area is the sum of the area of the cap discs, and the lateral surface area.

◆ Clip()

bool Cone::Clip ( const Quadric & q,
const double & u0,
const double & u1,
double & ta,
double & tb,
bool & sa,
bool & sb )
static

Compute the part of a ray which is inside a truncated cone, given the quadric of the infinite cone.

The point of the ray at depth t is inside the infinite cone if \( q(t) \le 0 \), where q is the difference between the squared distance of the point to the axis and the squared radius of the cone. If the leading coefficient of q is positive, the inside is between the two roots of q, as for a ray crossing the cone. If it is negative, which occurs for a ray whose direction is close to the axis, the inside is outside of the roots, and it is the whole line if q has no root.

The truncated cone is the part of the infinite cone which lies between two planes, crossed by the ray at the depths u0 and u1.

Parameters
qQuadric.
u0,u1Depths of the ray on the two planes, which should be sorted.
ta,tbDepths of the first and of the last intersection points.
sa,sbSet to true if the point is on the lateral surface of the cone, and to false if it is on one of the two planes.
Returns
True if the ray crosses the truncated cone.

◆ Inside()

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

Check if a point is inside or outside the cone.

Parameters
pPoint.

◆ Intersect() [1/3]

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

Compute the intersections between the cone and a ray.

Parameters
rayThe ray.
ta,tbIntersection depths.

◆ Intersect() [2/3]

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

Compute the intersections between the cone and a ray.

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

◆ Intersect() [3/3]

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

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

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

◆ Normal()

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

Computes the vector distance between the cone and a point.

Parameters
pPoint.

◆ R()

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

Compute the distance between a point and the cone.

Details appear in 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).

Parameters
pPoint.

◆ RandomDirection()

Vector Cone::RandomDirection ( const Vector & axis,
const double & alpha,
Random & random = Random::R239 )
static

Generate a random direction.

Parameters
axisAxis.
alphaAngle.
randomRandom number generator.

◆ RandomInside()

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

Generate a random vector inside the cone.

Parameters
randomRandom number generator.

◆ RayRange()

bool Cone::RayRange ( const Ray & ray,
const Vector & a,
const Vector & axis,
const double & length,
const double & ra,
const double & rlength,
double & ta,
double & tb,
bool & sa,
bool & sb )
static

Compute the depths of the intersection of a ray with a truncated cone.

The cone is defined by its first vertex, its axis, its length and the variation of its radius along the axis.

Parameters
rayThe ray.
aFirst vertex of the axis.
axisNormalized axis, from the first to the second vertex.
lengthLength of the axis.
raRadius at the first vertex.
rlengthVariation of the radius per unit of length along the axis.
ta,tbDepths of the first and of the last intersection points.
sa,sbSet to true if the point is on the lateral surface of the cone, and to false if it is on one of the two planes.
Returns
True if the ray crosses the cone.
See also
Cone::Clip

◆ Rotate()

void Cone::Rotate ( const Matrix & r)

Rotates the cone.

Parameters
rRotation matrix.

◆ Scale()

void Cone::Scale ( const double & s)

Uniformly scales the cone.

Parameters
sScaling factor.

◆ SideNormal()

Vector Cone::SideNormal ( const Vector & n,
const Vector & axis,
const double & rlength )
static

Compute the outward normal of the lateral surface of a cone.

The normal is the normalized gradient of the squared distance to the axis minus the squared radius.

Parameters
nVector from the first vertex of the axis to the point of the surface.
axisNormalized axis, from the first to the second vertex.
rlengthVariation of the radius per unit of length along the axis.
Returns
The normal, which is the opposite of the axis at the apex.

◆ Signed()

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

Compute the signed distance between a point and the cone.

Parameters
pPoint.

◆ Translate()

void Cone::Translate ( const Vector & t)

Translates the cone.

Parameters
tTranslation vector.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Cone & cone )
friend

Overloaded.

Parameters
sStream.
coneThe cone.