Core 1.0
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
Triangle2 Class Reference

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...
 

Detailed Description

Base minimum storage triangle class in the plane.

Constructor & Destructor Documentation

◆ Triangle2() [1/2]

Triangle2::Triangle2 ( const Vector2 a,
const Vector2 b,
const Vector2 c 
)
inlineexplicit

Create a triangle given three points.

Parameters
a,b,cVertices.

◆ Triangle2() [2/2]

Triangle2::Triangle2 ( const Triangle t)
explicit

Create a triangle.

Parameters
tTriangle.

Member Function Documentation

◆ Aspect()

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.

See also
Triangle::Aspect()

◆ BarycentricCoordinates()

Vector Triangle2::BarycentricCoordinates ( const Vector2 p) const

Compute the barycentric coordinates of an argument vector with respect to the triangle.

See also
Triangle::BarycentricCoordinates()
Parameters
pPoint.

◆ Circumscribed()

Circle2 Triangle2::Circumscribed ( ) const
inline

Compute the circle circumscribing the triangle.

This function directly relies on the constructor of the class.

See also
Circle2::Circle2(const Vector2&,const Vector2&,const Vector2&);

◆ Draw()

void Triangle2::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draw a triangle.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush, should the triangle be filled.

◆ Inscribed()

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.

◆ InscribedRadius()

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.

◆ Inside() [1/4]

bool Triangle2::Inside ( const Box2 box) const

Test if a box lies inside the triangle.

Parameters
boxThe box.

◆ Inside() [2/4]

bool Triangle2::Inside ( const Circle2 circle) const

Test if a circle lies inside the triangle.

Parameters
circleThe circle.

◆ Inside() [3/4]

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.

See also
Triangle2::Inside(const Vector2&,double&,double&)
Parameters
pPoint.

◆ Inside() [4/4]

bool Triangle2::Inside ( const Vector2 p,
double &  u,
double &  v 
) const

Test if a point lies inside the triangle and computes its uv-coordinates.

Parameters
pPoint.
u,vUV-coordinates.

◆ Intersect() [1/3]

bool Triangle2::Intersect ( const Circle2 circle) const

Check the intersection with a circle.

Parameters
circleThe circle.

◆ Intersect() [2/3]

bool Triangle2::Intersect ( const Ray2 ray,
double &  ta,
double &  tb 
) const

Compute the intersection with a ray.

Parameters
rayThe ray.
ta,tbIntersection depths

◆ Intersect() [3/3]

bool Triangle2::Intersect ( const Triangle2 t) const

Test if two triangles intersect.

Parameters
tTriangle.

Triangles should have their vertices in trigonometric order.

◆ IntersectEdge()

bool Triangle2::IntersectEdge ( const Triangle2 t) const
protected

Test if the edges of two triangles intersect.

Parameters
tTriangle.

◆ IntersectVertex()

bool Triangle2::IntersectVertex ( const Triangle2 t) const
protected

Test if two triangles are intersecting by performing a vertex intersection test.

Parameters
tTriangle.

Triangles should have their vertices in trigonometric order.

◆ Normal()

Vector2 Triangle2::Normal ( const Vector2 q) const

Computes the normal vector to a triangle.

Parameters
qPoint.

◆ Overlap()

bool Triangle2::Overlap ( const Triangle2 t) const

Test if two triangles overlap.

Parameters
tTriangle.

◆ R()

double Triangle2::R ( const Vector2 q) const

Computes the squared distance between a point and a triangle.

Parameters
qPoint.

◆ RandomInside()

Vector2 Triangle2::RandomInside ( Random random = Random::R239) const

Generate a random vector inside the triangle.

See also
Triangle::RandomInside
Parameters
randomRandom number generator.

◆ Rotate()

void Triangle2::Rotate ( const Matrix2 r)

Rotate the triangle.

Parameters
rRotation matrix.

◆ Scale() [1/2]

void Triangle2::Scale ( const double &  s)

Scale the triangle.

Parameters
sScaling factor.

◆ Scale() [2/2]

void Triangle2::Scale ( const Vector2 s)

Scale the triangle.

Parameters
sScaling vector.

◆ Shrink()

void Triangle2::Shrink ( const double &  e)

Shrinks a triangle.

Parameters
eErosion radius.

◆ Translate()

void Triangle2::Translate ( const Vector2 t)

Translate the triangle.

Parameters
tTranslation vector.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Triangle2 t 
)
friend

Overloaded.

Parameters
tTriangle.
sStream.