DelaunayTriangulation
A C++ Object Oriented data structure with algorithms that could be used to generate a Delaunay triangulation
Classes | Public Member Functions | Private Attributes | Friends | List of all members
Triangle Class Reference

Class representing a polygon with 3 points and its member functions. More...

#include <Triangle.hpp>

Collaboration diagram for Triangle:
Collaboration graph

Classes

struct  circumcircle
 Circumcircle object. More...
 

Public Member Functions

 Triangle ()
 Default constructor.
 
 Triangle (int index, IMesh *owner)
 Constructor populating index and owner. More...
 
 ~Triangle ()
 Default destructor.
 
void calcCircumcircle ()
 Calculate the circumcircle of the Triangle. More...
 
bool circumcircleContainsPoint (const Eigen::Vector2d &p) const
 Check if the circumcircle of the Triangle contains a point. More...
 
Eigen::Vector3d barycentric (const Eigen::Vector2d &p) const
 Get the barycentric coordinates of a point in relation to the triangle. More...
 
bool containsPoint (const Eigen::Vector2d &p) const
 Check if the Triangle contains a point. More...
 
double area () const
 Calculate the area of the triangle in 2d (x & y coords) More...
 
int getIndex () const
 Accessor for private member index. More...
 
void setIndex (int i)
 Mutator for private member index. More...
 
const std::vector< int > & getVertices () const
 Accessor for private member vertices. More...
 
void setVertices (const std::vector< int > &vertices)
 Mutator for private member vertices. More...
 
const std::vector< double > & getAttributes () const
 Accessor for private member attributes. More...
 
void setAttributes (const std::vector< double > &attributes)
 Mutator for private member attributes. More...
 
const circumcirclegetCc () const
 Accessor for private member cc. More...
 
void setCc (const circumcircle &cc)
 Mutator for private member cc. More...
 
const std::vector< IMesh::edge > & getEdges () const
 Accessor for private member edges. More...
 
void setEdges (const std::vector< IMesh::edge > &edges)
 Mutator for private member edges. More...
 
IMeshgetOwner () const
 Accessor for private member owner. More...
 
bool operator== (const Triangle &rhs) const
 Equality operator. More...
 
bool operator!= (const Triangle &rhs) const
 Non-equality operator. More...
 

Private Attributes

int index
 Index of the triangle (loaded from file)
 
circumcircle cc
 Circumcircle of the current triangle.
 
IMeshowner
 Pointer to interface class of the Mesh the Triangle is part of.
 
std::vector< double > attributes
 Vector of attributes of the Triangle (16 points of precision)
 
std::vector< IMesh::vertIndvertices
 Vector of vertex indices making up the Triangle.
 
std::vector< IMesh::edgeedges
 Vector of edges making up the Triangle.
 

Friends

std::istream & operator>> (std::istream &is, Triangle &triangle)
 Input stream operator. More...
 
std::ostream & operator<< (std::ostream &os, Triangle &triangle)
 Output stream operator. More...
 
std::ofstream & operator<< (std::ofstream &ofs, Triangle &triangle)
 Output filestream operator. More...
 

Detailed Description

Class representing a polygon with 3 points and its member functions.


Class Documentation

◆ Triangle::circumcircle

struct Triangle::circumcircle

Circumcircle object.

Collaboration diagram for Triangle::circumcircle:
Collaboration graph
Class Members
double radius radius of the circumcircle
double x x coordinate of the circumcentre
double y y coordinate of the circumcentre

Constructor & Destructor Documentation

◆ Triangle()

Triangle::Triangle ( int  index,
IMesh owner 
)
inline

Constructor populating index and owner.

Parameters
indexIndex of Triangle according to file
ownerPointer to Mesh the Triangle is a part of

Member Function Documentation

◆ area()

double Triangle::area ( ) const

Calculate the area of the triangle in 2d (x & y coords)

Returns
area of triangle

Area of triangle can be computed given a triangle with points represented by vector \( \mathbf{A, B, C}\)

\[ A_T = \frac{|\mathbf{A}-\mathbf{B}| |\mathbf{B}-\mathbf{C}|}{2} \]

◆ barycentric()

Eigen::Vector3d Triangle::barycentric ( const Eigen::Vector2d &  p) const

Get the barycentric coordinates of a point in relation to the triangle.

Parameters
p2 element double-precision Eigen3 vector storing the point in cartesian coordinates
Returns
3 element double-precision Eigen3 vector storing the poit in barycentric coordinates

Given a point \(r = \left(\begin{matrix}x \\ y\end{matrix}\right)\) and a Triangle made up of points \(r_1, r_2, r_3\) where \(r_i = \left(\begin{matrix}x_i\\ y_i\end{matrix}\right)\), the barycentric coordinates of p, \((\lambda_1, \lambda_2, \lambda_3)\) can be determined

\[ \left(\begin{matrix}\lambda_1 \\ \lambda_2\end{matrix}\right) = \left(\begin{matrix} x_1-x_3 & x_2-x_3 \\ y_1-y_3 & y_2-y_3 \\ \end{matrix}\right)^{-1} \left( \left(\begin{matrix}x \\ y\end{matrix}\right)-\left(\begin{matrix}x_3\\ y_3\end{matrix}\right) \right) \]

\[ \lambda_3 = 1 - \lambda_1 - \lambda_2 \]

◆ calcCircumcircle()

void Triangle::calcCircumcircle ( )

Calculate the circumcircle of the Triangle.

Given a Triangle made up of points \(r_1, r_2, r_3\) where \(r_i = \left(\begin{matrix}x_i\\ y_i\end{matrix}\right)\), the circumcentre of the triangle \((O_x, O_y)\) and the circumcircle's radius \(R\) can be found from

\[ \mathbf{O} = \left(\begin{matrix} 2O_x \\ 2O_y \\ R^2 - O_x^2 - O_y^2 \end{matrix}\right) \]

\[ \left(\begin{matrix} x_0^2 + y_0^2 \\ x_1^2 + y_1^2 \\ x_2^2 + y_2^2 \end{matrix}\right) = \mathbf{O}\left(\begin{matrix} x_0 & y_0 & 1 \\ x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \end{matrix}\right) \]

So by solving for \(\mathbf{O}\) the circumcircle's data can be found

◆ circumcircleContainsPoint()

bool Triangle::circumcircleContainsPoint ( const Eigen::Vector2d &  p) const

Check if the circumcircle of the Triangle contains a point.

Parameters
p2 element double-precision Eigen3 vector storing the point
Returns
Whether the circumcircle contains the point

Given a point \(\mathbf{p}\) and the centre of a circumcirclecircle \(\mathbf{c}\), its distance from the circumcentre can be found

\[ d = |\mathbf{p}-\mathbf{c}| \]

If \(d < \) circumcircle::radius then the point is inside the circumcircle

◆ containsPoint()

bool Triangle::containsPoint ( const Eigen::Vector2d &  p) const

Check if the Triangle contains a point.

Parameters
p2 element double-precision Eigen3 vector storing the point
Returns
Whether the triangle contains the point

First checks if point is inside pre-computed circumcircle, if it is, computes barycentric coordinates of the point If all barycentric coordinates \( \lambda_i >= 0\) then point is inside triangle

◆ getAttributes()

const std::vector< double > & Triangle::getAttributes ( ) const

Accessor for private member attributes.

Returns
vector of triangle attributes

◆ getCc()

const Triangle::circumcircle & Triangle::getCc ( ) const

Accessor for private member cc.

Returns
struct describing the circumcircle of the triangle

◆ getEdges()

const std::vector< std::pair< int, int > > & Triangle::getEdges ( ) const

Accessor for private member edges.

Returns
vector of edges making up the triangle

◆ getIndex()

int Triangle::getIndex ( ) const

Accessor for private member index.

Returns
index of Triangle or -1 if not part of mesh

◆ getOwner()

IMesh * Triangle::getOwner ( ) const

Accessor for private member owner.

Returns
pointer to owning Mesh interface class

◆ getVertices()

const std::vector< int > & Triangle::getVertices ( ) const

Accessor for private member vertices.

Returns
vector of vertex indices

◆ operator!=()

bool Triangle::operator!= ( const Triangle rhs) const

Non-equality operator.

Parameters
rhs
Returns

◆ operator==()

bool Triangle::operator== ( const Triangle rhs) const

Equality operator.

Parameters
rhs
Returns

◆ setAttributes()

void Triangle::setAttributes ( const std::vector< double > &  attributes)

Mutator for private member attributes.

Parameters
attributesvector of triangle attributes

◆ setCc()

void Triangle::setCc ( const circumcircle cc)

Mutator for private member cc.

Parameters
ccstruct describing the circumcircle of the triangle

◆ setEdges()

void Triangle::setEdges ( const std::vector< IMesh::edge > &  edges)

Mutator for private member edges.

Parameters
edgesvector of edges making up the triangle

◆ setIndex()

void Triangle::setIndex ( int  i)

Mutator for private member index.

Parameters
iindex of Triangle

◆ setVertices()

void Triangle::setVertices ( const std::vector< int > &  vertices)

Mutator for private member vertices.

Parameters
verticesvector of vertex indices

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ofstream & operator<< ( std::ofstream &  ofs,
Triangle triangle 
)
friend

Output filestream operator.

Parameters
ofs
triangle
Returns

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream &  os,
Triangle triangle 
)
friend

Output stream operator.

Parameters
os
triangle
Returns

◆ operator>>

std::istream & operator>> ( std::istream &  is,
Triangle triangle 
)
friend

Input stream operator.

Parameters
is
triangle
Returns

The documentation for this class was generated from the following files: