Class representing a polygon with 3 points and its member functions.
More...
#include <Triangle.hpp>
|
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.
|
|
|
std::istream & | operator>> (std::istream &is, Triangle &triangle) |
| Input stream operator.
|
|
std::ostream & | operator<< (std::ostream &os, Triangle &triangle) |
| Output stream operator.
|
|
std::ofstream & | operator<< (std::ofstream &ofs, Triangle &triangle) |
| Output filestream operator.
|
|
Class representing a polygon with 3 points and its member functions.
◆ Triangle::circumcircle
struct Triangle::circumcircle |
Class Members |
double |
radius |
radius of the circumcircle |
double |
x |
x coordinate of the circumcentre |
double |
y |
y coordinate of the circumcentre |
◆ Triangle()
Triangle::Triangle |
( |
int | index, |
|
|
IMesh * | owner ) |
|
inline |
Constructor populating index and owner.
- Parameters
-
◆ 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
-
p | 2 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
-
p | 2 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
-
p | 2 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()
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
-
- Returns
◆ operator==()
bool Triangle::operator== |
( |
const Triangle & | rhs | ) |
const |
Equality operator.
- Parameters
-
- Returns
◆ setAttributes()
void Triangle::setAttributes |
( |
const std::vector< double > & | attributes | ) |
|
Mutator for private member attributes.
- Parameters
-
attributes | vector of triangle attributes |
◆ setCc()
Mutator for private member cc.
- Parameters
-
cc | struct describing the circumcircle of the triangle |
◆ setEdges()
void Triangle::setEdges |
( |
const std::vector< IMesh::edge > & | edges | ) |
|
Mutator for private member edges.
- Parameters
-
edges | vector of edges making up the triangle |
◆ setIndex()
void Triangle::setIndex |
( |
int | i | ) |
|
Mutator for private member index.
- Parameters
-
◆ setVertices()
void Triangle::setVertices |
( |
const std::vector< int > & | vertices | ) |
|
Mutator for private member vertices.
- Parameters
-
vertices | vector of vertex indices |
◆ operator<< [1/2]
std::ofstream & operator<< |
( |
std::ofstream & | ofs, |
|
|
Triangle & | triangle ) |
|
friend |
Output filestream operator.
- Parameters
-
- Returns
◆ operator<< [2/2]
std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
Triangle & | triangle ) |
|
friend |
Output stream operator.
- Parameters
-
- Returns
◆ operator>>
std::istream & operator>> |
( |
std::istream & | is, |
|
|
Triangle & | triangle ) |
|
friend |
Input stream operator.
- Parameters
-
- Returns
The documentation for this class was generated from the following files: