Core 1.0
Octahedron Class Reference

An axis aligned octahedron. More...

#include <octahedron.h>

Public Member Functions

 Octahedron (const Vector &, const Vector &)
 Creates an octahedron given the vertices of its bounding box.
 Octahedron (const Vector &, const double &)
 Creates a regular octahedron given its center and radius.
 Octahedron (const double &)
 Creates a regular octahedron centered at the origin.
double Volume () const
 Compute the volume of the octahedron.
double Area () const
 Compute the area of the octahedron.
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
 Compute the normal to the i-th face as a normalized vector.
Vector Normal (const Vector &) const
 Compute the normal vector between a point and the octahedron.
double R (const Vector &) const
 Compute the squared Euclidean distance between a point and the octahedron.
double Signed (const Vector &) const
 Compute the signed Euclidean distance between a point and the octahedron.
Plane GetPlane (int) const
 Return the plane of the k-th face.
Box GetBox () const
 Return the bounding box of the octahedron.
bool Inside (const Vector &) const
 Check if a point is inside the octahedron.

Static Public Member Functions

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

Protected Attributes

Vector center = Vector::Null
 Center.
Vector half
 Half diagonal of the box.
Vector planenormal
 Normal to the plane in the first octant.
Vector ezxn
 Edge normals.

Static Protected Attributes

static const int face [8][3]
 Array of triangles.
static const Vector vertex [6]
 Array of internal vertexes for computing vertices.

Detailed Description

An axis aligned octahedron.

The octahedron is the convex hull of the six vertexes \( c \pm h_x e_x \), \( c \pm h_y e_y \) and \( c \pm h_z e_z \), where c is the center and \( (h_x,h_y,h_z) \) are the half diagonals, which are also the half sizes of its bounding box. It has eight triangular faces. Its volume and its area are:

\[V=\frac{4}{3}h_xh_yh_z, \quad A=4\|(h_yh_z,h_xh_z,h_xh_y)\|. \]

The octahedron is regular if the three half diagonals are equal.

Constructor & Destructor Documentation

◆ Octahedron() [1/3]

Octahedron::Octahedron ( const Vector & a,
const Vector & b )
explicit

Creates an octahedron given the vertices of its bounding box.

The center is the center of the box, and the half diagonals are its half sizes.

Parameters
a,bOpposite vertexes of the box.

◆ Octahedron() [2/3]

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

Creates a regular octahedron given its center and radius.

Parameters
cCenter.
rRadius, that is, the half diagonal along the three axes.

◆ Octahedron() [3/3]

Octahedron::Octahedron ( const double & r)
explicit

Creates a regular octahedron centered at the origin.

Parameters
rRadius, that is, the half diagonal along the three axes.

Member Function Documentation

◆ Area()

double Octahedron::Area ( ) const
inline

Compute the area of the octahedron.

It is 8 times the area of one of its triangular faces. The face with vertexes \( (h_x,0,0) \), \( (0,h_y,0) \) and \( (0,0,h_z) \) has an area equal to half the norm of the cross product of two of its edges, which is \( \frac{1}{2}\|(h_yh_z,h_xh_z,h_xh_y)\| \), so that the area of the octahedron is:

\[A=4\|(h_yh_z,h_xh_z,h_xh_y)\|. \]

The code has been optimized, instead of computing the normal of the triangle using Triangle::Normal(), the cross product has been inlined.

◆ GetPlane()

Plane Octahedron::GetPlane ( int k) const

Return the plane of the k-th face.

Parameters
kIndex.

◆ Inside()

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

Check if a point is inside the octahedron.

Parameters
pPoint.

◆ Normal()

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

Compute the normal vector between a point and the octahedron.

Parameters
pPoint.

◆ R()

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

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

Parameters
pThe point.

◆ Signed()

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

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

Parameters
pPoint.

◆ Volume()

double Octahedron::Volume ( ) const
inline

Compute the volume of the octahedron.

The octahedron is made of 8 tetrahedra, each one being defined by the center and by one of the 8 faces. Since the three edges of such a tetrahedron issued from the center are orthogonal, with lengths equal to the half diagonals \( h_x,h_y,h_z \), its volume is \( h_xh_yh_z/6 \), and the volume of the octahedron is:

\[V=\frac{4}{3}h_xh_yh_z, \]

that is, 1/6 the volume of the box \( 8h_xh_yh_z \) which bounds the octahedron.