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

Axis aligned box sphere. More...

#include <boxsphere.h>

Inheritance diagram for BoxSphere:
Box

Public Member Functions

 BoxSphere ()
 Empty.
 
 BoxSphere (const Box &, const double &=0.0)
 Create a box-sphere. More...
 
 BoxSphere (const Vector &, const Vector &, const double &=0.0)
 Create a box-sphere given two opposite corners and a radius. More...
 
 BoxSphere (const Vector &, const double &, const double &=0.0)
 Create a box sphere given a center point and the half side length. More...
 
 BoxSphere (const BoxSphere &, const BoxSphere &)
 Create a box-sphere embedding two box spheres. More...
 
 BoxSphere (const BoxSphere &, const Frame &)
 Creates a box-sphere. More...
 
 BoxSphere (const BoxSphere &, const Matrix &)
 Create a box-sphere. More...
 
 ~BoxSphere ()
 Empty.
 
Vectoroperator[] (int)
 Returns either end vertex of the box-sphere.
 
Vector operator[] (int) const
 Overloaded.
 
double Radius () const
 Returns the radius of the box-sphere. More...
 
double R (const Vector &) const
 Computes the squared distance between the box-sphere and a point. More...
 
double Signed (const Vector &) const
 Computes the signed distance between the box-sphere and a point. More...
 
int Intersect (const Ray &, double &, double &) const
 Computes the intersection between a box and a ray. More...
 
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersection between the object and a ray. More...
 
bool Inside (const Vector &) const
 Check if a point is inside the box-sphere. More...
 
double Volume () const
 Compute the volume of a box-sphere.
 
double Area () const
 Compute the area of a box-sphere.
 

Static Public Attributes

static constexpr const double epsilon = 1.0e-5
 Epsilon value.
 

Protected Attributes

double r
 Radius.
 
- Protected Attributes inherited from Box
Vector a
 Lower vertex.
 
Vector b
 Upper vertex.
 

Friends

BoxSphere operator+ (const BoxSphere &, const BoxSphere &)
 Compute the Minkowski sum of two box-spheres. More...
 
BoxSphere operator* (const double &, const BoxSphere &)
 Scale a box-sphere by a scalar factor. More...
 
BoxSphere operator* (const BoxSphere &, const double &)
 Overloaded. More...
 
std::ostream & operator<< (std::ostream &, const BoxSphere &)
 Overloaded. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Box
 Box ()
 Empty.
 
 Box (const double &)
 Create a cube centered at the origin and of given half side length. More...
 
 Box (const Vector &)
 Create an empty box given one vertex. More...
 
 Box (const Vector &, const Vector &)
 Create a box given two opposite corners. More...
 
 Box (const Vector &, const double &)
 Create a box given a center point and the half side length. More...
 
 Box (const Vector &, const double &, const double &, const double &)
 Create a box given a center point and its width, length, and height. More...
 
 Box (const double &, const double &, const double &)
 Create a box given its sizes. More...
 
 Box (const Vector *, int)
 Creates the bounding box of a set of points. More...
 
 Box (const QVector< Vector > &)
 Creates the bounding box of a set of points. More...
 
 Box (const Box &, const Box &)
 Create a box embedding two boxes. More...
 
 Box (const Box &, const Frame &)
 Creates an axis aligned bounding box from a box and a frame. More...
 
 Box (const Box &, const FrameScaled &)
 Creates an axis aligned bounding box from a box and a frame. More...
 
 Box (const Box &, const Matrix &)
 Creates an axis aligned bounding box from a box and a transformation matrix. More...
 
 ~Box ()
 Empty.
 
Vectoroperator[] (int)
 Returns either end vertex of the box.
 
Vector operator[] (int) const
 Overloaded.
 
Vector Center () const
 Returns the center of the box.
 
Vector Vertex (int) const
 Returns the k-th vertex of the box. More...
 
Vector Vertex (int, int, int, int, int, int) const
 Compute the coordinates of a grid aligned point. More...
 
Segment Edge (int) const
 Compute the k-th edge segment of the box. More...
 
Plane Face (int) const
 Compute the k-th plane of the box. More...
 
Vector Size () const
 Compute the size (width, length and height) of a box. More...
 
Vector Diagonal () const
 Returns the diagonal of the box.
 
double Radius () const
 Returns the radius of the box, i.e. the length of the half diagonal of the box.
 
double R (const Vector &) const
 Computes the squared Euclidean distance between the box and a point. More...
 
double Signed (const Vector &) const
 Computes the signed distance between the box and a point. More...
 
Vector Normal (const Vector &) const
 Computes the normal vector between a point and a box. More...
 
double R (const Box &) const
 Compute the squared Euclidean distance between two boxes. More...
 
double RInfinity (const Box &) const
 Compute the maximum distance between two boxes. More...
 
int Intersect (const Ray &) const
 Check the intersection between a box and a ray. More...
 
int Intersect (const Ray &, double &, double &) const
 Computes the intersection between a box and a ray. More...
 
int Intersect (const Ray &, double &) const
 Compute the first positive intersection between the box and a ray. More...
 
int Intersect (const Ray &, double &, double &, Vector &, Vector &) const
 Compute the intersection between an axis aligned box and a ray. More...
 
int Intersect (const Ray &, double &, Vector &) const
 Compute the first positive intersection between the box and a ray. More...
 
int Intersect (const Vector &, const Vector &) const
 Check if a segment intersects an axis aligned box. More...
 
bool Intersect (const Box &) const
 Check if the box intersects another box. More...
 
bool Inside (const Box &) const
 Check if an argument box is inside the box. More...
 
bool Inside (const Vector &) const
 Check if a point is inside the box. More...
 
Box Intersection (const Box &) const
 Computes the intersection between two boxes. More...
 
int Difference (const Box &, Box *) const
 Computes the difference between two boxes. More...
 
bool Empty () const
 Check if a box is empty. More...
 
double Volume () const
 Compute the volume of a box.
 
double Area () const
 Compute the surface area of a box.
 
void SetCubic ()
 Creates the tightest embedding cube from an arbitrarilly shaped box. More...
 
void SetInscribedCubic ()
 Creates the biggest cube iscribed in the box. More...
 
Box Cube () const
 Return the tightest embedding cube from an arbitrarilly shaped box. More...
 
void Extend (const double &)
 Extend the limits of the box by a given distance. More...
 
Box Extended (const double &) const
 Extend the limits of the box by a given distance. More...
 
void Extend (const Vector &)
 Extend the limits of the box given a point. More...
 
void SetParallelepipedic (const double &, int &, int &, int &)
 Creates a parallelepipedic box whose dimensions are integer multiples of a given input reference size. More...
 
void SetParallelepipedic (int, int &, int &, int &)
 Inflates a box so that its dimensions should be a fraction of its maximum side length. More...
 
Box Sub (int) const
 Computes the sub-box in the n-th octant. More...
 
int Octant (const Vector &) const
 Compute the octant index of a vertex with respect to the box center. More...
 
void Translate (const Vector &)
 Translates a box. More...
 
Box Translated (const Vector &) const
 Translated box. More...
 
void Scale (const double &)
 Scales a box. More...
 
void Scale (const Vector &)
 Scales a box. More...
 
Box Scaled (const Vector &) const
 Scales a box and return the scaled box. More...
 
Box Offsetted (const Vector &) const
 Offets a box. More...
 
Box Centered () const
 Compute the box translated to origin. More...
 
Box Cut (const Vector &, const Vector &) const
 Compute the minimal box embedding the box cut by half space. More...
 
int IntegerAxis () const
 Compute the axis which has the greater length.
 
Vector RandomInside (Random &=Random::R239) const
 Generate a random vector inside the box. More...
 
Vector RandomSurface (Random &=Random::R239) const
 Generate a random vector on the surface of the box. More...
 
QVector< VectorPoisson (const double &, int, Random &=Random::R239) const
 Compute a Poisson sphere distribution inside a box. More...
 
- Static Protected Attributes inherited from Box
static constexpr const double epsilon = 1.0e-5
 Epsilon value used to check intersections and some round off errors and for ray intersection tests.
 
static const Box Infinity
 Largest box. More...
 
static const Box Null
 Null box, equivalent to: More...
 
static const Box Unit
 Unit box.
 
static const int edge [24]
 Edge vertex indexes.
 
static const Vector normal [6]
 Face normals.
 

Detailed Description

Axis aligned box sphere.

This object is defined as a rounded axis aligned box, i.e., the Minkowski sum between a box and a sphere.

The class stores the opposite corners as vectors, and a radius.

This class provides a set of functions, such as the intersection between a box and a ray, and implements the Minkowski sum by overloading some operators.

Constructor & Destructor Documentation

◆ BoxSphere() [1/6]

BoxSphere::BoxSphere ( const Box box,
const double &  r = 0.0 
)
explicit

Create a box-sphere.

Parameters
boxThe box.
rRadius.

◆ BoxSphere() [2/6]

BoxSphere::BoxSphere ( const Vector a,
const Vector b,
const double &  r = 0.0 
)
explicit

Create a box-sphere given two opposite corners and a radius.

Note that this constructor does not check the coordinates of the two vectors.

Parameters
a,bEnd vertices.
rRadius.

◆ BoxSphere() [3/6]

BoxSphere::BoxSphere ( const Vector c,
const double &  a,
const double &  r = 0.0 
)
explicit

Create a box sphere given a center point and the half side length.

Parameters
cCenter.
aHalf side length.
rRadius.

◆ BoxSphere() [4/6]

BoxSphere::BoxSphere ( const BoxSphere x,
const BoxSphere y 
)
explicit

Create a box-sphere embedding two box spheres.

Parameters
x,yThe two box-spheres.

◆ BoxSphere() [5/6]

BoxSphere::BoxSphere ( const BoxSphere box,
const Frame frame 
)
explicit

Creates a box-sphere.

Parameters
boxThe box-sphere.
frameThe frame.

◆ BoxSphere() [6/6]

BoxSphere::BoxSphere ( const BoxSphere box,
const Matrix matrix 
)
explicit

Create a box-sphere.

Parameters
boxThe box-sphere.
matrixTransformation matrix.

Member Function Documentation

◆ Inside()

bool BoxSphere::Inside ( const Vector p) const

Check if a point is inside the box-sphere.

Parameters
pPoint.

◆ Intersect() [1/2]

int BoxSphere::Intersect ( const Ray ray,
double &  ta,
double &  tb 
) const

Computes the intersection between a box and a ray.

Sorted intersection depths are returned if intersection occurs.

Parameters
rayThe ray.
ta,tbIntersection depths.

◆ Intersect() [2/2]

int BoxSphere::Intersect ( const Ray ray,
double &  ta,
double &  tb,
Vector na,
Vector nb 
) const

Compute the intersection between the object and a ray.

Parameters
rayThe ray.
ta,tbIntersection depths.
na,nbReturned normals at intersection points.
Returns
The number of intersections.

◆ R()

double BoxSphere::R ( const Vector p) const

Computes the squared distance between the box-sphere and a point.

See also
Box::R(const Vector&) const
Parameters
pPoint.

◆ Radius()

double BoxSphere::Radius ( ) const
inline

Returns the radius of the box-sphere.

Note that this function differs from Box::Radius() which returns the radius of a box.

◆ Signed()

double BoxSphere::Signed ( const Vector p) const

Computes the signed distance between the box-sphere and a point.

The computation is derived from the signed distance to the box:

double d=Box::Signed(p)-r;
double Signed(const Vector &) const
Computes the signed distance between the box and a point.
Definition: box.cpp:389
double r
Radius.
Definition: boxsphere.h:12
Parameters
pPoint.

Friends And Related Function Documentation

◆ operator* [1/2]

BoxSphere operator* ( const BoxSphere box,
const double &  t 
)
friend

Overloaded.

Parameters
boxThe box-sphere.
tScalar.

◆ operator* [2/2]

BoxSphere operator* ( const double &  t,
const BoxSphere box 
)
friend

Scale a box-sphere by a scalar factor.

Parameters
boxThe box-sphere.
tScalar.

◆ operator+

BoxSphere operator+ ( const BoxSphere a,
const BoxSphere b 
)
friend

Compute the Minkowski sum of two box-spheres.

Parameters
a,bThe box-spheres.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const BoxSphere box 
)
friend

Overloaded.

Parameters
sStream.
boxThe sphere-box.