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

A dodecahedron. More...

#include <dodecahedron.h>

Public Member Functions

 Dodecahedron (const double &=1.0)
 Create a dodecahedron. More...
 
 Dodecahedron (const Vector &, const double &)
 Create a dodecahedron. More...
 
double Volume () const
 Compute the volume of the dodecahedron.
 
double Area () const
 Compute the area of the dodecahedron.
 
double Radius () const
 Compute the radius of the circmscribed sphere of the dodecahedron.
 
Vector Vertex (int) const
 Return the i-th vertex. More...
 
Vector Vertex (int, int) const
 Return the j-th vertex of the i-th face. More...
 
Vector Normal (int) const
 Return the normal to the i-th face as a normalized vector. More...
 
Box GetBox () const
 Return the bounding box of the shape.
 
Plane GetPlane (int) const
 Return the plane of the k-th face. More...
 
bool Inside (const Vector &) const
 Check if a point is inside. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the dodecahedron. More...
 
double Signed (const Vector &) const
 Compute the approximate signed distance to the dodecahedron. More...
 
bool Intersect (const Ray &, double &, double &, int &, int &) const
 Compute the intersection between a dodecahedron and a ray. More...
 

Static Public Member Functions

static constexpr int VertexIndex (int, int)
 Return the index of the j-th vertex of the i-th face. More...
 

Protected Attributes

Vector c = Vector::Null
 Center of dodecahedron.
 
double r = 1.0
 Radius.
 

Static Protected Attributes

static const double R2 = sqrt(3.0)
 Radius of the circumscribed sphere of an dodecahedron with edge length 2.0/Phi.
 
static const double Phi = (1 + sqrt(5.0)) / 2.0
 Golden ratio.
 
static const Vector vertex [20]
 Array of vertices.
 
static const Vector normal [12]
 Array of normals.
 
static const int face [12][5]
 Array of pentagons.
 

Detailed Description

A dodecahedron.

The following Cartesian coordinates define the vertices of a dodecahedron with edge-length 2/ φ, centered at the origin.

( ± 1, ± 1, ± 1)

(0, ± 1/ φ, ± φ)

( ± 1/ φ, ± φ, 0)

( ± φ, 0, ± 1/ φ)

where φ=(1+sqrt(5))/2 is the golden ratio.

Constructor & Destructor Documentation

◆ Dodecahedron() [1/2]

Dodecahedron::Dodecahedron ( const double &  r = 1.0)
explicit

Create a dodecahedron.

Parameters
rRadius.

◆ Dodecahedron() [2/2]

Dodecahedron::Dodecahedron ( const Vector c,
const double &  r 
)
explicit

Create a dodecahedron.

Parameters
cCenter.
rRadius.

Member Function Documentation

◆ GetPlane()

Plane Dodecahedron::GetPlane ( int  k) const

Return the plane of the k-th face.

Parameters
kIndex.

◆ Inside()

bool Dodecahedron::Inside ( const Vector p) const

Check if a point is inside.

Parameters
pThe point.

◆ Intersect()

bool Dodecahedron::Intersect ( const Ray ray,
double &  ta,
double &  tb,
int &  fa,
int &  fb 
) const

Compute the intersection between a dodecahedron and a ray.

Intersect the ray with the planes corresponding to the faces of the convex dodecahedron.

Parameters
rayThe ray.
ta,tbIntersection depths.
fa,fbIndex of the intersected faces.

◆ Normal()

Vector Dodecahedron::Normal ( int  i) const
inline

Return the normal to the i-th face as a normalized vector.

Parameters
iIndex.

◆ RandomInside()

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

Generate a random vector inside the dodecahedron.

Uses a simple rejection method.

Parameters
randomRandom number generator.

◆ Signed()

double Dodecahedron::Signed ( const Vector p) const

Compute the approximate signed distance to the dodecahedron.

Parameters
pPoint.

◆ Vertex() [1/2]

Vector Dodecahedron::Vertex ( int  i) const
inline

Return the i-th vertex.

Parameters
iIndex.

◆ Vertex() [2/2]

Vector Dodecahedron::Vertex ( int  i,
int  j 
) const
inline

Return the j-th vertex of the i-th face.

Parameters
iFace (pentagon).
jIndex representing the j-th vertex of the face.

◆ VertexIndex()

constexpr int Dodecahedron::VertexIndex ( int  i,
int  j 
)
inlinestaticconstexpr

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

Parameters
iFace (pentagon).
jIndex representing the j-th vertex of the face.