|
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 and compute the circle of intersection. | |
| bool | Intersect (const Sphere &) const |
| Check if two spheres intersect. | |
| bool | SurfaceIntersect (const Sphere &) const |
| Check if two spheres intersect, only considering their surface. | |
| 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 surface of the sphere. | |
| Vector2 | Euler (const Vector &) const |
| Compute the spherical (Euler) coordinates of a point relative to the sphere. | |
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 bool | Intersection (const Sphere &, const Sphere &, const Vector &, Vector &, Vector &) |
| Compute the intersection of two spheres and a plane. | |
Static Public Attributes | |
| static const double | epsilon = 1.0e-6 |
| \( \varepsilon \) 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.
The sphere of an empty set of points is the null sphere, centered at the origin, with a null radius.
| 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 spherical (Euler) coordinates of a point relative to the sphere.
The point p is first projected onto the unit sphere centered at c by computing the unit direction vector \(\mathbf{u} = \mathrm{Normalized}(p - c)\). The two angles are then:
| p | Point in world space (need not lie on the sphere surface). |
Vector2(theta, phi) with angles in radians. | 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 and compute the circle of intersection.
The spheres intersect if the distance between the centers is between the absolute value of the difference of the radii and the sum of the radii. There is then a circle of intersection, in the plane orthogonal to the line of the centers. The plane may be outside of the segment joining the centers, if the radii are very different.
The function returns false if the spheres are concentric, as there is no circle of intersection (there are infinitely many common points if the radii are equal).
| sphere | Sphere. |
| circle | Returned Circle, whose axis is the normalized vector from the center of the other sphere to the center of this sphere. |
|
static |
Compute the intersection of three spheres.
| sa,sb,sc | Spheres. |
| u,v | Returned points. |
|
static |
Compute the intersection of two spheres and a plane.
| sa,sb | Spheres. |
| n | Unit normal of the plane containing both centers, should be orthogonal to the direction between the centers. |
| 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 surface 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. |
| bool Sphere::SurfaceIntersect | ( | const Sphere & | sphere | ) | const |
Check if two spheres intersect, only considering their surface.
| sphere | Sphere. |
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 the volume of the lens is computed.
For two spheres of radii \( R \) and \( r \) whose centers are at distance \( d \), with \( |R-r|<d<R+r \), the volume of the intersection is:
\[V=\frac{\pi(R+r-d)^2\left(d^2+2dr-3r^2+2dR+6rR-3R^2\right)}{12d}. \]
| sphere | The other sphere. |
|
friend |
Overloaded.
| s | Stream. |
| sphere | The sphere. |