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

A simple tetrahedron. More...

#include <tetrahedra.h>

Public Member Functions

 Tetrahedra ()
 Empty.
 
 Tetrahedra (const Vector &, const Vector &, const Vector &, const Vector &)
 Creates a tetrahedron. More...
 
 Tetrahedra (const Box &, int)
 Returns the k-th tetrahedron of the box. More...
 
 ~Tetrahedra ()
 Empty.
 
Vector Vertex (int) const
 Returns the i-thvertex of the tetrahedron. More...
 
Triangle GetTriangle (int) const
 Returns the i-th triangle of the tetrahedron. More...
 
Plane GetPlane (int) const
 Returns the i-th plane of the tetrahedron. More...
 
Vector Normal (int) const
 Returns the normal of the i-th triangle of the tetrahedron. More...
 
constexpr int VertexIndex (int, int) const
 Return the index of the j-th vertex of the i-th triangle. More...
 
Vector Normal (const Vector &) const
 Computes the vector distance between the tetrahedron and a point. More...
 
Vector Normal2 (const Vector &) const
 Computes the vector distance between the tetrahedron and a point. More...
 
double R (const Vector &) const
 Computes the squared distance between the tetrahedron and a point. More...
 
double Signed (const Vector &) const
 Computes the signed distance between the tetrahedron and a point. More...
 
double Volume () const
 Compute the volume of a tetrahedron. More...
 
double Area () const
 Compute the surface area of a tetrahedron. More...
 
Box GetBox () const
 Compute the bounding box of a tetrahedron.
 
Sphere GetSphere () const
 Compute the sphere bounding the argument tetrahedron. More...
 
Tetrahedra Scaled (const Vector &) const
 Scale the tetrahedron. More...
 
Tetrahedra Scaled (const double &) const
 Uniform scaling. More...
 
Tetrahedra Translated (const Vector &) const
 Translate the tetrahedron. More...
 
Tetrahedra Rotated (const Matrix &) const
 Rotate the tetrahedron. More...
 
bool Intersect (const Ray &, double &, double &) const
 Compute the intersection between tetrahedra and a ray. More...
 
bool Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersection between tetrahedra and a ray. More...
 
bool Inside (const Vector &) const
 Check if a point lies inside the tetrahedron. More...
 
bool Intersect (const Tetrahedra &) const
 Check if two tetrahedra overlap. More...
 
bool Inside (const Plane &) const
 Compute if the tetrahedra is inside a half plane. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random point inside the tetrahedron. More...
 

Static Public Attributes

static double epsilon = 1e-7
 Internal epsilon constant.
 

Protected Attributes

Vector p [4]
 Array of vertices.
 
Vector n [4]
 Normals to the faces.
 

Static Protected Attributes

static const int vertex [4][3]
 Array of indexes defining the faces of the tetrahedron.
 
static const int split [6][4]
 Indexes of the vertexes of the sub-tetrahedron of a cube.
 

Friends

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

Detailed Description

A simple tetrahedron.

The class stores the vertices, the normals of the triangles, and the unit vectors of the edges.

This class also implements some useful functions, such as the intersection with a ray. The member function GetSphere() used to compute the bounding sphere of a tetrahedron simply calls the right Sphere constructor.

Constructor & Destructor Documentation

◆ Tetrahedra() [1/2]

Tetrahedra::Tetrahedra ( const Vector a,
const Vector b,
const Vector c,
const Vector d 
)
explicit

Creates a tetrahedron.

Note that vertices should be ordered so that triangle normals should point outward.

Parameters
a,b,c,dVertices.

◆ Tetrahedra() [2/2]

Tetrahedra::Tetrahedra ( const Box box,
int  k 
)
explicit

Returns the k-th tetrahedron of the box.

The box is divided into six tetrahedra.

Parameters
boxThe box.
kIndex of the tetrahedron.

Member Function Documentation

◆ Area()

double Tetrahedra::Area ( ) const

Compute the surface area of a tetrahedron.

The surface is defined as the sum of the surface areas of its four triangle faces. Other techniques define the surface area as:
A=(u+v+w).(v-w+u).(w-u+v).(u-v+w)
Here u, v and w denote the three edges length.

◆ GetPlane()

Plane Tetrahedra::GetPlane ( int  i) const

Returns the i-th plane of the tetrahedron.

Parameters
iIndex.

◆ GetSphere()

Sphere Tetrahedra::GetSphere ( ) const

Compute the sphere bounding the argument tetrahedron.

This is convenience function, simply calling the constructor of Sphere with four vertices.

See also
Sphere(const Vector&, const Vector&,const Vector&, const Vector&)

◆ GetTriangle()

Triangle Tetrahedra::GetTriangle ( int  i) const
inline

Returns the i-th triangle of the tetrahedron.

Parameters
iIndex.

◆ Inside() [1/2]

bool Tetrahedra::Inside ( const Plane plane) const

Compute if the tetrahedra is inside a half plane.

Parameters
planeThe plane.

◆ Inside() [2/2]

bool Tetrahedra::Inside ( const Vector p) const

Check if a point lies inside the tetrahedron.

Parameters
pPoint.

◆ Intersect() [1/3]

bool Tetrahedra::Intersect ( const Ray ray,
double &  ta,
double &  tb 
) const

Compute the intersection between tetrahedra and a ray.

Sorted intersection depths are returned if intersection occurs.

Parameters
rayThe ray.
ta,tbIntersection depths.

◆ Intersect() [2/3]

bool Tetrahedra::Intersect ( const Ray ray,
double &  ta,
double &  tb,
Vector na,
Vector nb 
) const

Compute the intersection between tetrahedra and a ray.

Sorted intersection depths are returned if intersection occurs.

Parameters
rayThe ray.
ta,tbReturned intersection depths.
na,nbReturned normals at intersection points.

◆ Intersect() [3/3]

bool Tetrahedra::Intersect ( const Tetrahedra T) const

Check if two tetrahedra overlap.

After F. Ganovelli, F. Ponchio, and C. Rocchini. Fast tetrahedron-tetrahedron overlap algorithm. Journal of Graphics Tools, 7(2):17-26, 2002.

Parameters
TArgument tetrahedron.

◆ Normal() [1/2]

Vector Tetrahedra::Normal ( const Vector x) const

Computes the vector distance between the tetrahedron and a point.

Parameters
xPoint.

◆ Normal() [2/2]

Vector Tetrahedra::Normal ( int  i) const
inline

Returns the normal of the i-th triangle of the tetrahedron.

Parameters
iIndex.

◆ Normal2()

Vector Tetrahedra::Normal2 ( const Vector x) const

Computes the vector distance between the tetrahedron and a point.

Parameters
xPoint.

◆ R()

double Tetrahedra::R ( const Vector x) const

Computes the squared distance between the tetrahedron and a point.

Parameters
xPoint.

◆ RandomInside()

Vector Tetrahedra::RandomInside ( Random r = Random::R239) const

Generate a random point inside the tetrahedron.

The method proposed here is a generalization of one of the techniques used by Turk to generate a random point inside a triangle. Generate a random point in a parallelogram and reflectit around the center of the parallelogram.

After C. Rocchini and P. Cignoni, Generating random points in a tetrahedron, Journal of graphics tools, 5(4):9-12, 2000.

Parameters
rRandom number generator.

◆ Rotated()

Tetrahedra Tetrahedra::Rotated ( const Matrix r) const

Rotate the tetrahedron.

Parameters
rRotation matrix.

◆ Scaled() [1/2]

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

Uniform scaling.

Parameters
sScaling factor.

◆ Scaled() [2/2]

Tetrahedra Tetrahedra::Scaled ( const Vector s) const

Scale the tetrahedron.

Parameters
sScaling vector.

◆ Signed()

double Tetrahedra::Signed ( const Vector x) const

Computes the signed distance between the tetrahedron and a point.

This function does not generate an Euclidean distance.

Parameters
xPoint.

◆ Translated()

Tetrahedra Tetrahedra::Translated ( const Vector t) const

Translate the tetrahedron.

Parameters
tTranslation vector.

◆ Vertex()

Vector Tetrahedra::Vertex ( int  i) const
inline

Returns the i-thvertex of the tetrahedron.

Parameters
iIndex.

◆ VertexIndex()

constexpr int Tetrahedra::VertexIndex ( int  i,
int  j 
) const
inlineconstexpr

Return the index of the j-th vertex of the i-th triangle.

Parameters
iTriangle index.
jVertex index.

◆ Volume()

double Tetrahedra::Volume ( ) const

Compute the volume of a tetrahedron.

The volume may be defined as one-sixth the volume of a parallelepiped whose three main edges emanate from a single vertex.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Tetrahedra t 
)
friend

Overloaded.

Parameters
sStream.
tThe tetrahedron.