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

A simple torus. More...

#include <torus.h>

Inheritance diagram for Torus:
Circle

Public Member Functions

 Torus (const Vector &, const Vector &, const double &=1.0, const double &=1.0)
 Creates a torus. More...
 
 Torus (const Circle &, const double &=1.0)
 Create a torus. More...
 
 Torus (const double &, const double &=1.0)
 Create a horizontal torus centered at origin. More...
 
 ~Torus ()
 Empty.
 
int Intersect (const Ray &, double *, Vector *) const
 Computes the intersection depths and the normals between a ray and a torus. More...
 
bool Inside (const Vector &) const
 Check if a point is inside or outside the torus. More...
 
Box GetBox () const
 Computes the bounding box of a torus.
 
double R (const Vector &) const
 Compute the squared Euclidean distance between a point and the torus. More...
 
double Signed (const Vector &) const
 Compute the signed Euclidean distance between a point and the torus. More...
 
Vector Normal (const Vector &) const
 Computes the distance vector between a torus and a given point. More...
 
double Area () const
 Compute the surface area of a torus.
 
double Volume () const
 Compute the volume of a torus.
 
double Small () const
 Return the small radius of the torus. More...
 
void Scale (const double &)
 Uniformly scales a torus. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the dodecahedron. More...
 
- Public Member Functions inherited from Circle
 Circle ()
 Empty.
 
 Circle (const double &)
 Creates a circle. More...
 
 Circle (const Vector &, const Vector &, const double &)
 Creates a circle. More...
 
 Circle (const Vector &, const Vector &, const Vector &)
 Creates a circle given three vertices. More...
 
 ~Circle ()
 Empty.
 
bool Intersect (const Ray &, double &) const
 Compute the ray-disc intersection. More...
 
Vector Center () const
 Gets the center of a circle.
 
Vector Axis () const
 Axis of the circle.
 
double Radius () const
 Radius of the circle.
 
double R (const Vector &) const
 Compute the distance between a point and a circle. More...
 
Vector Normal (const Vector &) const
 Computes the distance vector between a circle and a point. More...
 
void Rotate (const Matrix &)
 Rotates a circle. More...
 
void Translate (const Vector &)
 Transltes a circle. More...
 
void Scale (const double &)
 Uniformly scales a circle. More...
 
Box GetBox () const
 Compute the axis aligned bounding box of a circle. More...
 
double Area () const
 Area of a circle. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the circle. More...
 
Vector RandomOn (Random &=Random::R239) const
 Generate a random vector on the circle. More...
 

Static Public Attributes

static constexpr const double epsilon = 1e-06
 Epsilon constant for some inside-outside functions.
 
static const Torus Unit
 Unit vertical torus, major and minor radii equal to 1.
 

Protected Attributes

double s
 Small radius of the torus.
 
- Protected Attributes inherited from Circle
Vector c = Vector::Null
 Center of the circle.
 
Vector axis = Vector::Z
 Axis.
 
double r = 1.0
 Radius.
 

Friends

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

Additional Inherited Members

- Static Public Member Functions inherited from Circle
static double Area (const double &)
 Area of a circle given its radius. More...
 
- Static Protected Attributes inherited from Circle
static constexpr const double epsilon = 1.0e-10
 Internal epsilon constant.
 

Detailed Description

A simple torus.

The structure does not store the squared radius of the torus so as to save memory.

Rotation and translation are inherited from Circle.

Constructor & Destructor Documentation

◆ Torus() [1/3]

Torus::Torus ( const Vector c,
const Vector axis,
const double &  r = 1.0,
const double &  s = 1.0 
)
explicit

Creates a torus.

Parameters
cCenter.
axisAxis, which should be normalized.
rMajor radius.
sMinor (small) radius.

◆ Torus() [2/3]

Torus::Torus ( const Circle c,
const double &  s = 1.0 
)
explicit

Create a torus.

Parameters
cCircle.
sMinor (small) radius.

◆ Torus() [3/3]

Torus::Torus ( const double &  r,
const double &  s = 1.0 
)
explicit

Create a horizontal torus centered at origin.

Parameters
r,sMajor and minor radii.

Member Function Documentation

◆ Inside()

bool Torus::Inside ( const Vector p) const

Check if a point is inside or outside the torus.

Parameters
pPoint.

◆ Intersect()

int Torus::Intersect ( const Ray ray,
double *  depth,
Vector normal 
) const

Computes the intersection depths and the normals between a ray and a torus.

The quartic polynomial in t is derived from the canonical algebraic expression. Roots are found using the fast analytical Quartic::Solve() function of the Quartic class. This function returns an integer which is the number of intersections found. Note that intersections are sorted.

Parameters
rayThe ray.
depthArray of intersection depths.
normalArray of surface normals at intersection points.

◆ Normal()

Vector Torus::Normal ( const Vector p) const

Computes the distance vector between a torus and a given point.

This function projects the point in the plane of the circle and computes the distance to the circle in its plane, before adding the extra term along the normal.

Parameters
pPoint.

◆ R()

double Torus::R ( const Vector p) const

Compute the squared Euclidean distance between a point and the torus.

Parameters
pPoint.

◆ RandomInside()

Vector Torus::RandomInside ( Random random = Random::R239) const

Generate a random vector inside the dodecahedron.

Uses a simple rejection method.

Parameters
randomRandom number generator.

◆ Scale()

void Torus::Scale ( const double &  s)

Uniformly scales a torus.

Parameters
sScaling factor.

◆ Signed()

double Torus::Signed ( const Vector p) const

Compute the signed Euclidean distance between a point and the torus.

Parameters
pPoint.

◆ Small()

double Torus::Small ( ) const
inline

Return the small radius of the torus.

Use Torus::Radius() to get the major radius.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Torus torus 
)
friend

Overloaded.

Parameters
sStream.
torusThe torus.