|
Core 1.0
|
Axis aligned ellipses. More...
#include <ellipse.h>
Public Member Functions | |
| Ellipse2 () | |
| Empty. | |
| Ellipse2 (const Vector2 &, const double &, const double &, const Vector2 &=Vector2::X) | |
| Create an ellipse. | |
| Ellipse2 (const double &, const double &) | |
| Create an ellipse. | |
| Ellipse2 (const Matrix2 &, const Vector2 &) | |
| Create an ellipse. | |
| Ellipse2 (const Vector2 &, const Vector2 &, const double &) | |
| Create an ellipse from two points and a distance. | |
| ~Ellipse2 () | |
| Empty. | |
| Vector2 | Center () const |
| Gets the center. | |
| double | Radius () const |
| Return the equivalent radius of the ellipse. | |
| double | Length () const |
| Length. | |
| Vector2 | Axis () const |
| Return the major axis. | |
| Vector2 | Focus (bool) const |
| Return the focus points of the ellipse. | |
| double | A () const |
| Return the major axis length. | |
| double | B () const |
| Return the minor axis length. | |
| double | C () const |
| Return the half distance between the focus points of the ellipse. | |
| double | P () const |
| Return the parameter of the ellipse. | |
| Vector2 | Vertex (const double &) const |
| Compute a vertex on the ellipse. | |
| double | Curvature (const double &) const |
| Compute the curvature at a point of the ellipse. | |
| bool | Inside (const Vector2 &) const |
| Check if a point is inside the ellipse. | |
| Vector2 | Normal (const Vector2 &) const |
| Compute the distance vector between the ellipse and a point. | |
| double | R (const Vector2 &) const |
| Compute the squared distance between a point and the ellipse. | |
| double | Signed (const Vector2 &) const |
| Compute the signed distance between a point and the ellipse. | |
| Ellipse2 | Translated (const Vector2 &) const |
| Translate an ellipse. | |
| Ellipse2 | Scaled (const double &) const |
| Scales an ellipse. | |
| Ellipse2 | Scaled (const Vector2 &, bool=true) const |
| Scales an ellipse. | |
| Ellipse2 | Rotated (const double &) const |
| Rotates an ellipse. | |
| Ellipse2 | Rotated (const Matrix2 &) const |
| Rotates an ellipse. | |
| Ellipse2 | Transformed (const Frame2 &) const |
| Return a ellipse transformed by a frame. | |
| bool | Intersect (const Circle2 &) const |
| Check if a circle intersects an ellipse. | |
| double | Eccentricity () const |
| Eccentricity. | |
| double | Focus () const |
| Focus of an ellipse. | |
| Box2 | GetBox () const |
| Compute the bounding box. | |
| Circle2 | GetCircle () const |
| Compute the bounding circle. | |
| double | Area () const |
| Area of an ellipse. | |
| double | Perimeter () const |
| Perimeter of an ellipse. | |
| Vector2 | RandomInside (Random &=Random::R239) const |
| Generate a random vector inside the ellipse. | |
| QVector< Vector2 > | Poisson (const double &, int, Random &=Random::R239) const |
| Compute a Poisson disc distribution inside the ellipse. | |
| void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draw a circle. | |
| double | Value (const Vector2 &) const |
| Compute the field function value of an ellipse. | |
| Vector2 | Gradient (const Vector2 &) const |
| Compute the gradient of the field function. | |
Static Public Member Functions | |
| static Ellipse2 | Lerp (const double &, const Ellipse2 &, const Ellipse2 &) |
| Linear interpolation between two ellipses. | |
| static Ellipse2 | FromPoints (const std::vector< Vector2 > &points, double tolerance=0.05) |
| Builds a ellipse around a point cloud, using a Minium Volume Ellipsoid algorithm. | |
Protected Member Functions | |
| Matrix2 | MatrixForm () const |
| Compute the matrix form of the ellipse. | |
Protected Attributes | |
| Vector2 | c = Vector2::Null |
| Center of the ellipse. | |
| Vector2 | u = Vector2::X |
| Major axis. | |
| double | b = 1.0 |
| Axes lengths. | |
Friends | |
| std::ostream & | operator<< (std::ostream &s, const Ellipse2 &ellipse) |
| Overloaded. | |
Axis aligned ellipses.
|
explicit |
Create an ellipse.
| c | Center. |
| a,b | Axes lengths, should satisfy \( a>b \), if not we change the definition of the ellipse. |
| u | Major axis direction. |
|
explicit |
Create an ellipse.
| a,b | Axes lengths. |
Create an ellipse.
The ellipse is the set of points satisfying the equation: \( (p - c)^t . A . (p - c) = 1 \).
| A | Ellipse matrix (symmetric positive-definite). |
| c | Ellipse center. |
Create an ellipse from two points and a distance.
The ellipse is defined as the set: \( \|a-p\|+\|b-p\|=d \).
| a,b | The two foci. |
| d | Distance, should satisfy \( d > \|a - b\| \). |
| double Ellipse2::C | ( | ) | const |
Return the half distance between the focus points of the ellipse.
The focus points can be derived as:
| double Ellipse2::Curvature | ( | const double & | t | ) | const |
Compute the curvature at a point of the ellipse.
The point is given by its parameter: \( (a \cos t, b \sin t) \) in the local frame of the ellipse. The curvature is \( ab/(a^2 \sin^2 t+b^2 \cos^2 t)^{3/2} \), i.e. the inverse of the radius of curvature: it is a/b^2 at the end of the major axis, and b/a^2 at the end of the minor axis.
| t | Parameter angle of the point. |
| void Ellipse2::Draw | ( | QGraphicsScene & | scene, |
| const QPen & | pen = QPen(), | ||
| const QBrush & | brush = QBrush() ) const |
Draw a circle.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush, should the ellipse be filled. |
| Vector2 Ellipse2::Focus | ( | bool | i | ) | const |
Return the focus points of the ellipse.
| i | Index of the focus point, true for focus in the direction of the axis, false for the point in the opposite direction. |
Builds a ellipse around a point cloud, using a Minium Volume Ellipsoid algorithm.
| p | Points. |
| t | Tolerance. |
Compute the gradient of the field function.
The gradient of \( f(p)=\sqrt{x^2/a^2+y^2/b^2}-1 \) is not normalized, and it is expressed in the global frame. It is not defined at the center of the ellipse, where the vector Vector2::X is returned.
| p | Point. |
| bool Ellipse2::Inside | ( | const Vector2 & | p | ) | const |
Check if a point is inside the ellipse.
| p | Point. |
| bool Ellipse2::Intersect | ( | const Circle2 & | c | ) | const |
Check if a circle intersects an ellipse.
Internally, we compute the signed distance between the center of the circle and the ellipse, and check if it is smaller than the radius of the circle.
| c | Circle. |
Linear interpolation between two ellipses.
Linear interpolation of centers, radii, and main axis.
| t | Interpolant. |
| ea,eb | Ellipses. |
Compute the distance vector between the ellipse and a point.
The vector goes from the nearest point of the ellipse to the point, and is null inside the ellipse, as for Box2::Normal() and Disc2::Normal(). The projection of a point p onto the ellipse is therefore p-Normal(p).
The nearest point is computed with the closed form solution used by Ellipse2::R() and Ellipse2::Signed(), in the first quadrant of the frame of the ellipse, and then brought back to the point p by symmetry. The position of the nearest point is accurate to about 1e-6 (relative to the axes lengths), the distance to about 1e-10.
| p | Point. |
| double Ellipse2::Perimeter | ( | ) | const |
Perimeter of an ellipse.
The exact perimeter of an ellipse is 4 a E(e) where e is the eccentricity, and the function E is the complete elliptic integral of the second kind.
Here we use the first approximation proposed by Srinivasa Ramanujan, Modular Equations and Approximations to Pi: \( p \approx \pi \left( 3(a+b) - \sqrt{(3a+b)(a+3b)} \right) = \pi \left( 3(a+b) - \sqrt{10ab + 3(a^2+b^2)} \right) \), where \( a \) and \( b \) denote the semi-axes. The approximation is exact for a circle.
| QVector< Vector2 > Ellipse2::Poisson | ( | const double & | r, |
| int | n, | ||
| Random & | random = Random::R239 ) const |
Compute a Poisson disc distribution inside the ellipse.
This function uses a simple dart throwing algorithm.
| r | Radius of the discs. |
| n | Number of candidate points. |
| random | Random number generator. |
| double Ellipse2::R | ( | const Vector2 & | p | ) | const |
Compute the squared distance between a point and the ellipse.
| p | Point. |
|
inline |
Return the equivalent radius of the ellipse.
It is defined as \(r=\sqrt{ab} \)
| Vector2 Ellipse2::RandomInside | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector inside the ellipse.
| random | Random number generator. |
| Ellipse2 Ellipse2::Rotated | ( | const double & | a | ) | const |
Rotates an ellipse.
| a | Rotation angle. |
Rotates an ellipse.
| r | Rotation matrix. |
| Ellipse2 Ellipse2::Scaled | ( | const double & | s | ) | const |
Scales an ellipse.
| s | Scaling factor. |
Scales an ellipse.
| s | Scaling vector. |
| local | Boolean, set to true if scaling occurs in the local frame of the ellipse (default), otherwise computations are performed in the world coordinate system. |
| double Ellipse2::Signed | ( | const Vector2 & | p | ) | const |
Compute the signed distance between a point and the ellipse.
| p | Point. |
Return a ellipse transformed by a frame.
| f | Transformation. |
Translate an ellipse.
| t | Translation vector. |
| double Ellipse2::Value | ( | const Vector2 & | p | ) | const |
Compute the field function value of an ellipse.
| p | Point. |
| Vector2 Ellipse2::Vertex | ( | const double & | t | ) | const |
Compute a vertex on the ellipse.
| t | Angle. |
|
friend |
Overloaded.
| s | Stream. |
| ellipse | The ellipse. |