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 | 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. | |
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 area of the triangle. | |
double | Perimeter () const |
Compute the perimeter of the triangle. | |
Box2 | GetBox () const |
Computes the axis aligned box enclosing the triangle. | |
QVector< Vector2 > | Poisson (const double &, int, Random &=Random::R239) 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 (Random &=Random::R239) 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. | |
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. | |
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 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. |
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. This no longer holds if the point is outside of the triangle.
Note that this function is not the most efficient, as it relies on the evaluation of the area formed by the triangles pab, pbc, and pca.
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. |
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.
Some algebra will show that it is half the ratio of the half perimeter and the surface of the triangle.
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. |
bool Triangle2::Intersect | ( | const Ray2 & | ray, |
double & | ta, | ||
double & | tb ) const |
Compute the intersection with a ray.
ray | The ray. |
ta,tb | Intersection depths |
bool Triangle2::Intersect | ( | const Segment2 & | segment | ) | const |
Check the intersection with a segment.
segment | The segment. |
bool Triangle2::Intersect | ( | const Triangle2 & | t | ) | const |
Test if two triangles intersect.
t | Triangle. |
Triangles should have their vertices 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, | ||
Random & | random = Random::R239 ) 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 | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector inside the triangle.
random | Random number generator. |
void Triangle2::Rotate | ( | const Matrix2 & | r | ) |
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. |
void Triangle2::Shrink | ( | const double & | e | ) |
Shrinks a triangle.
e | Erosion radius. |
double Triangle2::SignedArea | ( | ) | const |
Compute the area of the triangle.
void Triangle2::Translate | ( | const Vector2 & | t | ) |
Translate the triangle.
t | Translation vector. |
|
friend |
Overloaded.
t | Triangle. |
s | Stream. |