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. More... | |
Triangle2 (const Triangle &) | |
Create a triangle. More... | |
~Triangle2 () | |
Empty. | |
Vector2 | operator[] (int) const |
Return the i-th vertex. | |
Vector2 | Center () const |
Compute the barycenter of the triangle. | |
Circle2 | Inscribed () const |
Compute the circle inscribed in the triangle. More... | |
Circle2 | Circumscribed () const |
Compute the circle circumscribing the triangle. More... | |
double | R (const Vector2 &) const |
Computes the squared distance between a point and a triangle. More... | |
Vector2 | Normal (const Vector2 &) const |
Computes the normal vector to a triangle. More... | |
bool | Intersect (const Circle2 &) const |
Check the intersection with a circle. More... | |
bool | Intersect (const Ray2 &, double &, double &) const |
Compute the intersection with a ray. More... | |
double | Area () 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. | |
Vector | BarycentricCoordinates (const Vector2 &) const |
Compute the barycentric coordinates of an argument vector with respect to the triangle. More... | |
double | InscribedRadius () const |
Compute the radius of the circle inscribed in the triangle. More... | |
double | CircumscribedRadius () const |
Compute the radius of the circumscribed circle of the triangle. | |
double | Aspect () const |
Computes the aspect ratio of the triangle. More... | |
bool | Inside (const Box2 &) const |
Test if a box lies inside the triangle. More... | |
bool | Inside (const Circle2 &) const |
Test if a circle lies inside the triangle. More... | |
bool | Inside (const Vector2 &) const |
Test if a point lies inside the triangle. More... | |
bool | Inside (const Vector2 &, double &, double &) const |
Test if a point lies inside the triangle and computes its uv-coordinates. More... | |
Vector2 | RandomInside (Random &=Random::R239) const |
Generate a random vector inside the triangle. More... | |
void | Rotate (const Matrix2 &) |
Rotate the triangle. More... | |
void | Translate (const Vector2 &) |
Translate the triangle. More... | |
void | Scale (const double &) |
Scale the triangle. More... | |
void | Scale (const Vector2 &) |
Scale the triangle. More... | |
void | Shrink (const double &) |
Shrinks a triangle. More... | |
bool | Overlap (const Triangle2 &) const |
Test if two triangles overlap. More... | |
bool | Intersect (const Triangle2 &) const |
Test if two triangles intersect. More... | |
void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
Draw a triangle. More... | |
Protected Member Functions | |
bool | IntersectEdge (const Triangle2 &) const |
Test if the edges of two triangles intersect. More... | |
bool | IntersectVertex (const Triangle2 &) const |
Test if two triangles are intersecting by performing a vertex intersection test. More... | |
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 &, const Triangle2 &) |
Overloaded. More... | |
Base minimum storage triangle class in the plane.
Create a triangle given three points.
a,b,c | Vertices. |
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 barycentric coordinates of an argument vector with respect to the triangle.
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. |
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 & | p | ) | const |
Test if a point lies inside the triangle.
This is an optimized version with some early tests to avoid some computations.
p | 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 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 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. |
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. |
void Triangle2::Translate | ( | const Vector2 & | t | ) |
Translate the triangle.
t | Translation vector. |
|
friend |
Overloaded.
t | Triangle. |
s | Stream. |