DelaunayTriangulation
A C++ Object Oriented data structure with algorithms that could be used to generate a Delaunay triangulation
|
Class representing a polygon with 3 points and its member functions. More...
#include <Triangle.hpp>
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 circumcircle & | getCc () 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... | |
IMesh * | getOwner () 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. | |
IMesh * | owner |
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::vertInd > | vertices |
Vector of vertex indices making up the Triangle. | |
std::vector< IMesh::edge > | edges |
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... | |
Class representing a polygon with 3 points and its member functions.
struct Triangle::circumcircle |
|
inline |
double Triangle::area | ( | ) | const |
Calculate the area of the triangle in 2d (x & y coords)
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} \]
Eigen::Vector3d Triangle::barycentric | ( | const Eigen::Vector2d & | p | ) | const |
Get the barycentric coordinates of a point in relation to the triangle.
p | 2 element double-precision Eigen3 vector storing the point in cartesian 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 \]
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
bool Triangle::circumcircleContainsPoint | ( | const Eigen::Vector2d & | p | ) | const |
Check if the circumcircle of the Triangle contains a point.
p | 2 element double-precision Eigen3 vector storing 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
bool Triangle::containsPoint | ( | const Eigen::Vector2d & | p | ) | const |
Check if the Triangle contains a point.
p | 2 element double-precision Eigen3 vector storing 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
const std::vector< double > & Triangle::getAttributes | ( | ) | const |
Accessor for private member attributes.
const Triangle::circumcircle & Triangle::getCc | ( | ) | const |
Accessor for private member cc.
const std::vector< std::pair< int, int > > & Triangle::getEdges | ( | ) | const |
Accessor for private member edges.
int Triangle::getIndex | ( | ) | const |
IMesh * Triangle::getOwner | ( | ) | const |
const std::vector< int > & Triangle::getVertices | ( | ) | const |
Accessor for private member vertices.
bool Triangle::operator!= | ( | const Triangle & | rhs | ) | const |
Non-equality operator.
rhs |
bool Triangle::operator== | ( | const Triangle & | rhs | ) | const |
Equality operator.
rhs |
void Triangle::setAttributes | ( | const std::vector< double > & | attributes | ) |
Mutator for private member attributes.
attributes | vector of triangle attributes |
void Triangle::setCc | ( | const circumcircle & | cc | ) |
Mutator for private member cc.
cc | struct describing the circumcircle of the triangle |
void Triangle::setEdges | ( | const std::vector< IMesh::edge > & | edges | ) |
Mutator for private member edges.
edges | vector of edges making up the triangle |
void Triangle::setVertices | ( | const std::vector< int > & | vertices | ) |
Mutator for private member vertices.
vertices | vector of vertex indices |
|
friend |
Output filestream operator.
ofs | |
triangle |
|
friend |
Output stream operator.
os | |
triangle |
|
friend |
Input stream operator.
is | |
triangle |