preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Triangle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <array>
6#include <iostream>
7#include <tuple>
8
10#include "mesh/Edge.hpp"
13#include "utils/assertion.hpp"
14
15namespace precice::mesh {
16class Vertex;
17}
18
19// ----------------------------------------------------------- CLASS DEFINITION
20
21namespace precice::mesh {
22
24class Triangle {
25public:
27
33
36
39
41 static constexpr int vertexCount{3};
42
45 Edge &edgeOne,
46 Edge &edgeTwo,
47 Edge &edgeThree);
48
55 Vertex &VertexOne,
56 Vertex &VertexTwo,
57 Vertex &VertexThree);
58
60 int getDimensions() const;
61
69 Vertex &vertex(int i);
70
78 const Vertex &vertex(int i) const;
79
82
85
87 iterator end();
88
90 const_iterator begin() const;
91
93 const_iterator end() const;
94
96 const_iterator cbegin() const;
97
99 const_iterator cend() const;
100
102
104 Eigen::VectorXd computeNormal() const;
105
107 double getArea() const;
108
110 const Eigen::VectorXd getCenter() const;
111
113 double getEnclosingRadius() const;
114
121 bool operator==(const Triangle &other) const;
122
124 bool operator!=(const Triangle &other) const;
125
127 bool operator<(const Triangle &other) const
128 {
129 return std::make_tuple(_vertices[0]->getID(), _vertices[1]->getID(), _vertices[2]->getID()) <
130 std::make_tuple(other._vertices[0]->getID(), other._vertices[1]->getID(), other._vertices[2]->getID());
131 }
132
133private:
136};
137
138// --------------------------------------------------------- HEADER DEFINITIONS
139
141{
142 PRECICE_ASSERT((i >= 0) && (i < 3), i);
143 return *_vertices[i];
144}
145
146inline const Vertex &Triangle::vertex(int i) const
147{
148 PRECICE_ASSERT((i >= 0) && (i < 3), i);
149 return *_vertices[i];
150}
151
153{
154 return {this, 0};
155}
156
158{
159 return {this, 3};
160}
161
163{
164 return {this, 0};
165}
166
168{
169 return {this, 3};
170}
171
173{
174 return begin();
175}
176
178{
179 return end();
180}
181
183
184} // namespace precice::mesh
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:15
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:24
double getArea() const
Returns the surface area of the triangle.
Definition Triangle.cpp:70
int getDimensions() const
Returns dimensionalty of space the triangle is embedded in.
Definition Triangle.cpp:84
std::array< Vertex *, 3 > _vertices
Vertices defining the triangle, sorted by Vertex::getID()
Definition Triangle.hpp:135
iterator begin()
Returns a read-only random-access iterator to the begin (0) of the vertex range [0,...
Definition Triangle.hpp:152
const_iterator cbegin() const
Returns a read-only random-access iterator to the begin (0) of the vertex range [0,...
Definition Triangle.hpp:172
bool operator<(const Triangle &other) const
Weak ordering based on vertex ids.
Definition Triangle.hpp:127
iterator end()
Returns a read-only random-access iterator to the end (3) of the vertex range [0,1,...
Definition Triangle.hpp:157
double getEnclosingRadius() const
Returns the radius of the circle enclosing the triangle.
Definition Triangle.cpp:94
Eigen::VectorXd computeNormal() const
Computes the normal of the triangle.
Definition Triangle.cpp:75
Vertex & vertex(int i)
Returns triangle vertex with index 0, 1 or 2.
Definition Triangle.hpp:140
const_iterator iterator
Type of the read-only random access vertex iterator.
Definition Triangle.hpp:35
bool operator==(const Triangle &other) const
Compares two Triangles for equality.
Definition Triangle.cpp:102
const Eigen::VectorXd getCenter() const
Returns the barycenter of the triangle.
Definition Triangle.cpp:89
const_iterator cend() const
Returns a read-only random access iterator to the end (3) of the vertex range [0,1,...
Definition Triangle.hpp:177
bool operator!=(const Triangle &other) const
Not equal, implemented in terms of equal.
Definition Triangle.cpp:108
IndexRangeIterator< const Triangle, const Vertex::RawCoords > const_iterator
Type of the read-only const random-access iterator over Vertex coords.
Definition Triangle.hpp:32
static constexpr int vertexCount
Amount of vertices.
Definition Triangle.hpp:41
Triangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Constructor based on 3 edges.
Definition Triangle.cpp:23
Vertex of a mesh.
Definition Vertex.hpp:16
std::array< double, 3 > RawCoords
Definition Vertex.hpp:19
T make_tuple(T... args)
provides Mesh, Data and primitives.
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)