|
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. | |
| Sphere (const Vector &, const double &=0.0) | |
| Creates a sphere given center and radius. | |
| Sphere (const Vector &, const Vector &) | |
| Creates a sphere given two points. | |
| Sphere (const Vector &, const Vector &, const Vector &) | |
| Creates a sphere given three vertices. | |
| Sphere (const Vector &, const Vector &, const Vector &, const Vector &) | |
| Create a sphere circumsizing four vertices. | |
| Sphere (const QVector< Vector > &) | |
| Compute the minimal bounding sphere of a set of points. | |
| ~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. | |
| int | Intersect (const Ray &, double &, double &) const |
| Compute the intersection between a sphere and a ray. | |
| int | Intersect (const Ray &, double &, double &, Vector &, Vector &) const |
| This function computes the intersections between a sphere and a ray. | |
| bool | Intersect (const Box &) const |
| Box-sphere intersection test. | |
| bool | Intersect (const Sphere &, Circle &) const |
| Check if two spheres intersect. | |
| bool | Intersect (const Sphere &) const |
| Check if two spheres intersect. | |
| bool | Intersect (const Ray &, double &) const |
| This function computes the first intersection between a sphere and a ray. | |
| bool | Inside (const Vector &) const |
| Check if a point is inside or outside the sphere. | |
| double | Volume () const |
| Compute the volume of the sphere. | |
| double | Volume (const Sphere &) const |
| Compute the volume of the intersection of two spheres. | |
| 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. | |
| double | R (const Vector &) const |
| Compute the squared distance between a point and the sphere. | |
| double | Signed (const Vector &) const |
| Compute the signed distance between a point and the sphere. | |
| double | R (const Sphere &) const |
| Compute the signed distance between two spheres. | |
| double | R (const Vector &, const Vector &) const |
| Compute the great-circle or orthodromic distance. | |
| void | Rotate (const Matrix &) |
| Rotates a sphere. | |
| void | Translate (const Vector &) |
| Translates a sphere. | |
| void | Scale (const double &) |
| Uniformly scales a sphere. | |
| Sphere | Translated (const Vector &) const |
| Translate a sphere. | |
| Sphere | Scaled (const Vector &) const |
| Scales a sphere by a given vector. | |
| Sphere | Rotated (const Matrix &) const |
| Rotates a sphere. | |
| Sphere | Transformed (const Frame &) const |
| Transforms a sphere. | |
| Sphere | InverseTransformed (const Frame &) const |
| Inverse transforms a sphere. | |
| void | Extend (const Vector &) |
| Extend the sphere so that the argument point should be embedded in the new sphere. | |
| void | Extend (const double &) |
| Extend the sphere, i.e. increase the radius of the sphere. | |
| Sphere | Extended (const double &) const |
| Extend the sphere, i.e. increase the radius of the sphere. | |
| Vector | RandomSurface (Random &=Random::R239) const |
| Generate a random point on the sphere. | |
| Vector | RandomInside (Random &=Random::R239) const |
| Generate a random vector inside the sphere. | |
| Vector | Fibonacci (int, int) const |
| QVector< Vector > | Poisson (const double &, int, Random &=Random::R239) const |
| Create a Poisson Disc sampling of the sphere. | |
| Vector2 | Euler (const Vector &) const |
| Compute the Euler coordinates of a point. | |
Static Public Member Functions | |
| static Vector | RandomNormal (Random &=Random::R239) |
| Generate a random unit vector orthonormal to the sphere. | |
| static double | Area (const double &) |
| Compute the surface area of a sphere. | |
| static double | Volume (const double &) |
| Compute the volume of a sphere. | |
| static Vector2 | EquiRectangular (int, int, int, int) |
| Compute the Euler coordinates of a point defined in a rectangle map. | |
| static bool | Intersection (const Sphere &, const Sphere &, const Sphere &, Vector &, Vector &) |
| Compute the intersection of three spheres. | |
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 &a, const Sphere &b) |
| Computes the Minkowski sum of two spheres. | |
| Sphere | operator* (const double &t, const Sphere &sphere) |
| Scales a sphere by a scalar factor. The homothetic sphere has a positive radius whatever the scaling factor. | |
| Sphere | operator* (const Sphere &sphere, const double &t) |
| Scales a sphere by a scalar factor. The homothetic sphere has a positive radius whatever the scaling factor. | |
| std::ostream & | operator<< (std::ostream &s, const Sphere &sphere) |
| Overloaded. | |
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. |
| void Sphere::Extend | ( | const Vector & | p | ) |
Extend the sphere so that the argument point should be embedded in the new sphere.
This is the same as computing the smallest enclosing sphere of a sphere and a point.
| p | Point. |
| 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.
In other words, phyllotaxic samples for nearly optimal distribution over a 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. |
Check if two spheres intersect.
If the centers are identical, then the spheres intersect if and only if their radii are equal. Otherwise, there exists a circle of intersection, the normal of the plane of intersection is derived from the centers of the spheres.
| sphere | Sphere. |
| circle | Returned Circle. |
|
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. |