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

An icosahedron. More...

#include <icosahedron.h>

Public Member Functions

 Icosahedron (const Vector &, const double &)
 Creates an icosahedron given its center and radius. More...
 
 Icosahedron (const double &=1.0)
 Creates an icosahedron. More...
 
double Volume () const
 Compute the volume of the icosahedron.
 
double Area () const
 Compute the area of the icosahedron.
 
double Radius () const
 Compute the radius of the circmscribed sphere of the icosahedron.
 
Vector Vertex (int) const
 Return the i-th vertex as a vector.
 
Vector Vertex (int, int) const
 Return the j-th vertex of the i-th face.
 
Vector Normal (int) const
 Return the normal to the i-th face as a normalized vector.
 
Box GetBox () const
 Return the bounding box.
 
Plane GetPlane (int) const
 Return the plane of the k-th face.
 
bool Inside (const Vector &) const
 Check if a point is inside. More...
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the icosahedron. More...
 
double Signed (const Vector &) const
 Compute the approximate signed distance to the icosahedron. More...
 
bool Intersect (const Ray &, double &, double &, int &, int &) const
 Compute the intersection between an icosahedron 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.
 
static constexpr int VertexEdgeIndex (int, int)
 Return the index of the j-th vertex of the i-th edge. More...
 

Protected Attributes

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

Static Protected Attributes

static const double R2 = (1.0 / 4.0) * sqrt(10 + 2.0 * sqrt(5.0)) * 2.0
 Radius of the circumscribed sphere of an icosahedron with edge length 2.
 
static const double Phi = (1 + sqrt(5.0)) / 2.0
 Phi.
 
static const Vector vertex [12]
 Array of vertices.
 
static const Vector normal [20]
 Array of normals.
 
static const int edge [30][2]
 Array of edges.
 
static const int face [20][3]
 Array of pentagons.
 

Detailed Description

An icosahedron.

The following Cartesian coordinates define the vertices of an icosahedron with edge-length 2, centered at the origin.

(0, ± 1, ± φ)

( ± 1, ± φ,0)

( ± φ,0, ± 1)

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

Constructor & Destructor Documentation

◆ Icosahedron() [1/2]

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

Creates an icosahedron given its center and radius.

Parameters
cCenter.
rRadius.

◆ Icosahedron() [2/2]

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

Creates an icosahedron.

Parameters
rRadius.

Member Function Documentation

◆ Inside()

bool Icosahedron::Inside ( const Vector p) const

Check if a point is inside.

Parameters
pThe point.

◆ Intersect()

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

Compute the intersection between an icosahedron and a ray.

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

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

◆ RandomInside()

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

Generate a random vector inside the icosahedron.

Uses a simple rejection method.

Parameters
randomRandom number generator.

◆ Signed()

double Icosahedron::Signed ( const Vector p) const

Compute the approximate signed distance to the icosahedron.

Parameters
pPoint.

◆ VertexEdgeIndex()

constexpr int Icosahedron::VertexEdgeIndex ( int  i,
int  j 
)
inlinestaticconstexpr

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

Parameters
iEdge.
jVertex (should be O or 1).