Core 1.0
|
Spheres. More...
#include <sphere.h>
Public Member Functions | |
Sphere () | |
Empty. | |
Sphere (const double &) | |
Creates a sphere centered at origin with specified radius. More... | |
Sphere (const Vector &, const double &=0.0) | |
Creates a sphere given center and radius. More... | |
Sphere (const Vector &, const Vector &) | |
Creates a sphere given two points. More... | |
Sphere (const Vector &, const Vector &, const Vector &) | |
Creates a sphere given three vertices. More... | |
Sphere (const Vector &, const Vector &, const Vector &, const Vector &) | |
Create a sphere circumsizing four vertices. More... | |
Sphere (const QVector< Vector > &) | |
Compute the minimal bounding sphere of a set of points. More... | |
~Sphere () | |
Empty. | |
Vector | Center () const |
Gets the center of a sphere. | |
double | Radius () const |
Gets the radius of a sphere. | |
Box | GetBox () const |
Compute the bounding box of a sphere. | |
bool | Intersect (const Ray &) const |
Check the intersection between a sphere and a ray. More... | |
int | Intersect (const Ray &, double &, double &) const |
Compute the intersection between a sphere and a ray. More... | |
int | Intersect (const Ray &, double &, double &, Vector &, Vector &) const |
This function computes the intersections between a sphere and a ray. More... | |
bool | Intersect (const Box &) const |
Box-sphere intersection test. More... | |
bool | Intersect (const Sphere &, Circle &) const |
Check if two spheres intersect. More... | |
bool | Intersect (const Sphere &) const |
Check if two spheres intersect. More... | |
bool | Intersect (const Ray &, double &) const |
This function computes the first intersection between a sphere and a ray. More... | |
bool | Inside (const Vector &) const |
Check if a point is inside or outside the sphere. More... | |
double | Volume () const |
Compute the volume of the sphere. | |
double | Volume (const Sphere &) const |
Compute the volume of the intersection of two spheres. More... | |
double | Area () const |
Compute the surface area of a sphere. | |
Vector | Normal (const Vector &) const |
Computes the normal vector between a point and the sphere. More... | |
double | R (const Vector &) const |
Compute the squared distance between a point and the sphere. More... | |
double | Signed (const Vector &) const |
Compute the signed distance between a point and the sphere. More... | |
double | R (const Sphere &) const |
Compute the signed distance between two spheres. More... | |
double | R (const Vector &, const Vector &) const |
Compute the great-circle or orthodromic distance. More... | |
void | Rotate (const Matrix &) |
Rotates a sphere. More... | |
void | Translate (const Vector &) |
Translates a sphere. More... | |
void | Scale (const double &) |
Uniformly scales a sphere. More... | |
Sphere | Translated (const Vector &) const |
Translate a sphere. More... | |
Sphere | Scaled (const Vector &) const |
Scales a sphere by a given vector. More... | |
Sphere | Rotated (const Matrix &) const |
Rotates a sphere. More... | |
Sphere | Transformed (const Frame &) const |
Transforms a sphere. More... | |
Sphere | InverseTransformed (const Frame &) const |
Inverse transforms a sphere. More... | |
void | Extend (const double &) |
Extend the sphere, i.e. increase the radius of the sphere. More... | |
Sphere | Extended (const double &) const |
Extend the sphere, i.e. increase the radius of the sphere. More... | |
Vector | RandomSurface (Random &=Random::R239) const |
Generate a random point on the sphere. More... | |
Vector | RandomInside (Random &=Random::R239) const |
Generate a random vector inside the sphere. More... | |
Vector | Fibonacci (int, int) const |
QVector< Vector > | Poisson (const double &, int, Random &=Random::R239) const |
Create a Poisson Disc sampling of the sphere. More... | |
Vector2 | Euler (const Vector &) const |
Compute the Euler coordinates of a point. More... | |
Static Public Member Functions | |
static Vector | RandomNormal (Random &=Random::R239) |
Generate a random unit vector orthonormal to the sphere. More... | |
static double | Area (const double &) |
Compute the surface area of a sphere. More... | |
static double | Volume (const double &) |
Compute the volume of a sphere. More... | |
static Vector2 | EquiRectangular (int, int, int, int) |
Compute the Euler coordinates of a point defined in a rectangle map. More... | |
static bool | Intesection (const Sphere &, const Sphere &, const Sphere &, Vector &, Vector &) |
Compute the intersection of three spheres. More... | |
Static Public Attributes | |
static const double | epsilon = 1.0e-4 |
ε for intersection tests. | |
static const Sphere | Null |
Empty sphere. | |
static const Sphere | Infinity |
Infinite sphere. | |
static const Sphere | Unit |
Unit sphere. | |
Protected Attributes | |
Vector | c = Vector::Null |
Center. | |
double | r = 0.0 |
Radius. | |
Friends | |
Sphere | operator+ (const Sphere &, const Sphere &) |
Computes the Minkowski sum of two spheres. | |
Sphere | operator* (const double &, const Sphere &) |
Scales a sphere by a scalar factor. The homothetic sphere has a positive radius whatever the scaling factor. | |
Sphere | operator* (const Sphere &, const double &) |
Scales a sphere by a scalar factor. The homothetic sphere has a positive radius whatever the scaling factor. | |
std::ostream & | operator<< (std::ostream &, const Sphere &) |
Overloaded. More... | |
Spheres.
Spheres are defined by their center and radius. The squared radius is not stored in the data-structure, and is computed on the fly whenever needed.
This class implements several high level functions to compute the minimal bounding sphere of a set of points. It also implements the Minkowski sum of two spheres.
The sphere-ray intersection functions assume that the ray is normalized, i.e. has a unit direction vector.
|
explicit |
Creates a sphere centered at origin with specified radius.
r | Radius. |
|
explicit |
Creates a sphere given center and radius.
c | Center. |
r | Radius. |
Creates a sphere given two points.
Basically set the center to the middle of the segment and set the radius to the half length of the segment.
a,b | The two vertices. |
Creates a sphere given three vertices.
Set the center to the center of the triangle, and compute the corresponding radius. Note that the argument vertices should not be aligned.
x,y,z | The three vertices. |
|
explicit |
Create a sphere circumsizing four vertices.
This is the same as a sphere bounding a tetrahedron.
p0,p1,p2,p3 | Argument vertices |
|
explicit |
Compute the minimal bounding sphere of a set of points.
Error around 1%~2%. Based on Bo Tian, Bouncing bubble: a fast algorithm for minimal enclosing pall problem, 2012.
p | Set of points. |
|
inlinestatic |
Compute the surface area of a sphere.
r | Radius. |
|
static |
Compute the Euler coordinates of a point defined in a rectangle map.
i,j | Point coordinates. |
x,y | Size of the map. |
Compute the Euler coordinates of a point.
p | Point. |
void Sphere::Extend | ( | const double & | e | ) |
Extend the sphere, i.e. increase the radius of the sphere.
Contrary to Scale, this function does not change the center.
e | Radius change. |
Sphere Sphere::Extended | ( | const double & | e | ) | const |
Extend the sphere, i.e. increase the radius of the sphere.
e | Radius change. |
Vector Sphere::Fibonacci | ( | int | i, |
int | n | ||
) | const |
Compute the i-th point of the Fibonacci distribution of points on the sphere.
i | Point index. |
n | Number of samples on the sphere. |
bool Sphere::Inside | ( | const Vector & | p | ) | const |
Check if a point is inside or outside the sphere.
p | The point. |
bool Sphere::Intersect | ( | const Box & | box | ) | const |
Box-sphere intersection test.
The algorithm calculates the square of the distance from the box to the sphere by analyzing the orientation of the sphere relative to the box in a single loop. If the box is not axis aligned, transform the center of the sphere to the box's local coordinate frame.
After J. Arvo, A simple method for box-sphere intersection testing, In A. Glassner, Graphics Gems: 335-339, Academic Press 1990.
bool Sphere::Intersect | ( | const Ray & | ray | ) | const |
Check the intersection between a sphere and a ray.
Note that intersections are sorted.
This function assumes that the ray is normalized, i.e. has a unit direction vector.
ray | The (normalized) ray. |
bool Sphere::Intersect | ( | const Ray & | ray, |
double & | t | ||
) | const |
This function computes the first intersection between a sphere and a ray.
This function assumes that the ray is normalized, i.e., has a unit direction vector.
ray | The (normalized) ray. |
t | Returned intersection depth. |
int Sphere::Intersect | ( | const Ray & | ray, |
double & | ta, | ||
double & | tb | ||
) | const |
Compute the intersection between a sphere and a ray.
Note that intersections are sorted.
This function assumes that the ray is normalized, i.e. has a unit direction vector.
ray | The (normalized) ray. |
ta,tb | Intersection depths. |
This function computes the intersections between a sphere and a ray.
The intersections are sorted.
This function assumes that the ray is normalized, i.e. has a unit direction vector.
ray | The (normalized) ray. |
ta,tb | Intersection depths. |
na,nb | Normals at intersection points. |
bool Sphere::Intersect | ( | const Sphere & | sphere | ) | const |
Check if two spheres intersect.
sphere | Sphere. |
|
static |
Compute the intersection of three spheres.
sa,sb,sc | Spheres. |
u,v | Returned points. |
Inverse transforms a sphere.
t | Transformation. |
Computes the normal vector between a point and the sphere.
Simply project point onto the sphere, and return the corresponding Euclidean distance vector.
p | Point. |
QVector< Vector > Sphere::Poisson | ( | const double & | r, |
int | n, | ||
Random & | random = Random::R239 |
||
) | const |
Create a Poisson Disc sampling of the sphere.
Simple dart throwing algorithm.
r | Radius of the discs. |
n | Maximum number of darts thrown on the sphere. |
random | Random number generator. |
double Sphere::R | ( | const Sphere & | s | ) | const |
Compute the signed distance between two spheres.
If the spheres intersect, the result is negative.
s | The other Sphere. |
double Sphere::R | ( | const Vector & | p | ) | const |
Compute the squared distance between a point and the sphere.
p | The point. |
Compute the great-circle or orthodromic distance.
It is the geodesic distance between two points on the surface of a sphere.
This function is computationnally intensive, requiring several square root and inverse trigonometric function evaluations.
a,b | Points on the sphere. |
Vector Sphere::RandomInside | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector inside the sphere.
random | Random number generator. |
|
static |
Generate a random unit vector orthonormal to the sphere.
random | Random number generator. |
Vector Sphere::RandomSurface | ( | Random & | random = Random::R239 | ) | const |
Generate a random point on the sphere.
random | Random number generator. |
void Sphere::Rotate | ( | const Matrix & | r | ) |
Rotates a sphere.
r | Rotation matrix. |
void Sphere::Scale | ( | const double & | s | ) |
Uniformly scales a sphere.
s | Scaling factor. |
Scales a sphere by a given vector.
Since the sphere may become an ellipsoid, compute the enclosing sphere.
s | Scaling vector. |
double Sphere::Signed | ( | const Vector & | p | ) | const |
Compute the signed distance between a point and the sphere.
p | The point. |
Transforms a sphere.
t | Transformation. |
void Sphere::Translate | ( | const Vector & | t | ) |
Translates a sphere.
t | Translation vector. |
Translate a sphere.
t | Translation vector. |
|
inlinestatic |
Compute the volume of a sphere.
r | Radius. |
double Sphere::Volume | ( | const Sphere & | sphere | ) | const |
Compute the volume of the intersection of two spheres.
If the spheres do not intersect, the function returns 0; if the smallest is included in the largest, the function returns the volume of the smallest, otherwise complex computations are performed.
sphere | The other sphere. |
|
friend |
Overloaded.
s | Stream. |
sphere | The sphere. |