|
Core 1.0
|
Base minimum storage triangle class in the plane. More...
#include <triangle.h>
Public Member Functions | |
| Triangle2 () | |
| Empty. | |
| Triangle2 (const Vector2 &, const Vector2 &, const Vector2 &) | |
| Create a triangle given three points. | |
| Triangle2 (const Triangle &) | |
| Create a triangle. | |
| ~Triangle2 () | |
| Empty. | |
| Vector2 | operator[] (int) const |
| Return the i-th vertex. | |
| Vector2 & | operator[] (int) |
| Return a reference to the i-th vertex. | |
| Vector2 | Center () const |
| Compute the barycenter of the triangle. | |
| Vector2 | BaryCenter (const Vector &) const |
| Compute the barycenter given barycentric coordinates. | |
| Vector2 | OrthoCenter () const |
| Compute the orthocenter. | |
| Circle2 | Inscribed () const |
| Compute the circle inscribed in the triangle. | |
| Circle2 | Circumscribed () const |
| Compute the circle circumscribing the triangle. | |
| double | R (const Vector2 &) const |
| Computes the squared distance between a point and a triangle. | |
| double | Signed (const Vector2 &) const |
| Computes the signed Euclidean distance between a point and a triangle. | |
| Vector2 | Normal (const Vector2 &) const |
| Computes the normal vector to a triangle. | |
| bool | Intersect (const Circle2 &) const |
| Check the intersection with a circle. | |
| bool | Intersect (const Box2 &) const |
| Check the intersection with a box. | |
| bool | Intersect (const Segment2 &) const |
| Check the intersection with a segment. | |
| bool | Intersect (const Ray2 &, double &, double &) const |
| Compute the intersection with a ray. | |
| double | Area () const |
| Compute the area of the triangle. | |
| double | SignedArea () const |
| Compute the signed area of the triangle. | |
| double | Perimeter () const |
| Compute the perimeter of the triangle. | |
| Box2 | GetBox () const |
| Computes the axis aligned box enclosing the triangle. | |
| OrientedBox2 | GetOrientedBox () const |
| Computes the oriented box enclosing the triangle. | |
| QVector< Vector2 > | Poisson (const double &, int, Xoshiro256 &=Xoshiro256::X512) const |
| Compute a Poisson disc distribution inside the triangle. | |
| Vector | BarycentricCoordinates (const Vector2 &) const |
| Compute the barycentric coordinates of an argument vector with respect to the triangle. | |
| double | InscribedRadius () const |
| Compute the radius of the circle inscribed in the triangle. | |
| double | CircumscribedRadius () const |
| Compute the radius of the circumscribed circle of the triangle. | |
| double | Aspect () const |
| Computes the aspect ratio of the triangle. | |
| bool | Inside (const Box2 &) const |
| Test if a box lies inside the triangle. | |
| bool | Inside (const Circle2 &) const |
| Test if a circle lies inside the triangle. | |
| bool | Inside (const Vector2 &) const |
| Test if a point lies inside the triangle. | |
| bool | Inside (const Vector2 &, double &, double &) const |
| Test if a point lies inside the triangle and computes its uv-coordinates. | |
| Vector2 | RandomInside (Xoshiro256 &=Xoshiro256::X512) const |
| Generate a random vector inside the triangle. | |
| void | Rotate (const Matrix2 &) |
| Rotate the triangle. | |
| void | Translate (const Vector2 &) |
| Translate the triangle. | |
| void | Scale (const double &) |
| Scale the triangle. | |
| void | Scale (const Vector2 &) |
| Scale the triangle. | |
| Triangle2 | Rotated (const Matrix2 &) const |
| Rotate the triangle. | |
| Triangle2 | Translated (const Vector2 &) const |
| Translate the triangle. | |
| Triangle2 | Scaled (const double &) const |
| Scale the triangle. | |
| Triangle2 | Scaled (const Vector2 &) const |
| Scale the triangle. | |
| void | Shrink (const double &) |
| Shrinks a triangle. | |
| bool | Overlap (const Triangle2 &) const |
| Test if two triangles overlap. | |
| bool | Intersect (const Triangle2 &) const |
| Test if two triangles intersect. | |
| Triangle2 | Trigonometric () const |
| Return a triangle whose vertexes are guaranteed to be in trigonometric order. | |
| void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draw a triangle. | |
Static Public Member Functions | |
| static Triangle2 | Equilateral (const Vector2 &, const double &=1.0, const double &=0.0) |
| Create an equilateral triangle. | |
Protected Member Functions | |
| bool | IntersectEdge (const Triangle2 &) const |
| Test if the edges of two triangles intersect. | |
| bool | IntersectVertex (const Triangle2 &) const |
| Test if two triangles are intersecting by performing a vertex intersection test. | |
Protected Attributes | |
| Vector2 | p [3] |
| Array of vertices. | |
Static Protected Attributes | |
| static constexpr double | epsilon = 1.0e-7 |
| Internal epsilon constant. | |
Friends | |
| std::ostream & | operator<< (std::ostream &s, const Triangle2 &t) |
| Overloaded. | |
Base minimum storage triangle class in the plane.
Create a triangle given three points.
| a,b,c | Vertices. |
|
explicit |
| double Triangle2::Area | ( | ) | const |
Compute the area of the triangle.
| double Triangle2::Aspect | ( | ) | const |
Computes the aspect ratio of the triangle.
The aspect ratio is defined as twice the radius of the inscribed circle divided by the radius of the circumscribing circle.
Compute the barycenter given barycentric coordinates.
| weights | Weights. |
Compute the barycentric coordinates of an argument vector with respect to the triangle.
If the point lies within the triangle, the coordinates are positive and form a partition of the unity. If the point is outside of the triangle, the coordinates still sum to one, but some of them are negative, so that BaryCenter(BarycentricCoordinates(p)) returns p.
The coordinates are the ratios of the signed areas of the triangles obtained by replacing in turn each vertex by the point. The result is undefined (division by zero) if the triangle is degenerate.
Note that this function is not the most efficient.
| p | Point. |
|
inline |
Compute the circle circumscribing the triangle.
This function directly relies on the constructor of the class.
| void Triangle2::Draw | ( | QGraphicsScene & | scene, |
| const QPen & | pen = QPen(), | ||
| const QBrush & | brush = QBrush() ) const |
Draw a triangle.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush, should the triangle be filled. |
|
static |
Create an equilateral triangle.
| c | Center. |
| r | Radius. |
| a | Rotation angle. |
| OrientedBox2 Triangle2::GetOrientedBox | ( | ) | const |
Computes the oriented box enclosing the triangle.
The box is aligned with the longest edge of the triangle.
| Circle2 Triangle2::Inscribed | ( | ) | const |
Compute the circle inscribed in the triangle.
The center of the circle is the center of (A,a), (B,b) and (C,c) where A, B and C are the vertices of the triangle and coefficients a, b and c represent the length of their facing edge.
| double Triangle2::InscribedRadius | ( | ) | const |
Compute the radius of the circle inscribed in the triangle.
It is the ratio of the area to the half perimeter of the triangle, i.e. twice the area divided by the perimeter.
| bool Triangle2::Inside | ( | const Box2 & | box | ) | const |
Test if a box lies inside the triangle.
| box | The box. |
| bool Triangle2::Inside | ( | const Circle2 & | circle | ) | const |
Test if a circle lies inside the triangle.
| circle | The circle. |
| bool Triangle2::Inside | ( | const Vector2 & | q | ) | const |
Test if a point lies inside the triangle.
| q | Point. |
| bool Triangle2::Inside | ( | const Vector2 & | p, |
| double & | u, | ||
| double & | v ) const |
Test if a point lies inside the triangle and computes its uv-coordinates.
| p | Point. |
| u,v | UV-coordinates. |
| bool Triangle2::Intersect | ( | const Box2 & | box | ) | const |
Check the intersection with a box.
| box | The box. |
| bool Triangle2::Intersect | ( | const Circle2 & | circle | ) | const |
Check the intersection with a circle.
| circle | The circle. |
The test computes the signed distance from the circle center to the edges via Triangle2::R(), which iterates over all three edges unconditionally:
No pre-rejection is performed; the full edge-distance computation always runs.
| bool Triangle2::Intersect | ( | const Ray2 & | ray, |
| double & | ta, | ||
| double & | tb ) const |
Compute the intersection with a ray.
The ray is considered as an infinite line: the depths may be negative. The function works for both orientations of the triangle.
| ray | The ray. |
| ta,tb | Depths of the entry and exit points, with ta < tb if the function returns true. |
| bool Triangle2::Intersect | ( | const Segment2 & | segment | ) | const |
Check the intersection with a segment.
Only the boundary of the triangle is tested: a segment strictly inside the triangle does not intersect it. Use Inside() on one of its end points to detect this case.
| segment | The segment. |
| bool Triangle2::Intersect | ( | const Triangle2 & | t | ) | const |
Test if two triangles intersect.
| t | Triangle. |
Alogithm, based on the separating axis theorem, test the normal of each edge of the triangles as a potential separating axis.
Triangles should have their vertices stored in trigonometric order.
|
protected |
Test if the edges of two triangles intersect.
| t | Triangle. |
|
protected |
Test if two triangles are intersecting by performing a vertex intersection test.
| t | Triangle. |
Triangles should have their vertices in trigonometric order.
Computes the normal vector to a triangle.
| q | Point. |
| bool Triangle2::Overlap | ( | const Triangle2 & | t | ) | const |
Test if two triangles overlap.
| t | Triangle. |
| QVector< Vector2 > Triangle2::Poisson | ( | const double & | r, |
| int | n, | ||
| Xoshiro256 & | random = Xoshiro256::X512 ) const |
Compute a Poisson disc distribution inside the triangle.
This function uses a simple dart throwing algorithm.
| r | Radius of the discs. |
| n | Number of candidate points. |
| random | Random number generator. |
| double Triangle2::R | ( | const Vector2 & | q | ) | const |
Computes the squared distance between a point and a triangle.
| q | Point. |
| Vector2 Triangle2::RandomInside | ( | Xoshiro256 & | random = Xoshiro256::X512 | ) | const |
Generate a random vector inside the triangle.
| random | Random number generator. |
| void Triangle2::Rotate | ( | const Matrix2 & | r | ) |
Rotate the triangle.
| r | Rotation matrix. |
Rotate the triangle.
| r | Rotation matrix. |
| void Triangle2::Scale | ( | const double & | s | ) |
Scale the triangle.
| s | Scaling factor. |
| void Triangle2::Scale | ( | const Vector2 & | s | ) |
Scale the triangle.
| s | Scaling vector. |
| Triangle2 Triangle2::Scaled | ( | const double & | s | ) | const |
Scale the triangle.
| s | Scaling factor. |
Scale the triangle.
| s | Scaling vector. |
| void Triangle2::Shrink | ( | const double & | e | ) |
Shrinks a triangle.
| e | Erosion radius. |
| double Triangle2::Signed | ( | const Vector2 & | q | ) | const |
Computes the signed Euclidean distance between a point and a triangle.
| q | Point. |
| double Triangle2::SignedArea | ( | ) | const |
Compute the signed area of the triangle.
The area is positive if the vertexes are in trigonometric (counter-clockwise) order, and negative otherwise.
| void Triangle2::Translate | ( | const Vector2 & | t | ) |
Translate the triangle.
| t | Translation vector. |
Translate the triangle.
| t | Translation vector. |
|
friend |
Overloaded.
| t | Triangle. |
| s | Stream. |