23#include <external/Eigen/Dense>
39 edge_polarities_ = edge_polarities;
42 centroid_ = centroid(v_);
53 v_2d.col(0) << 0.0, 0.0;
56 if (
v_2d.col(1)[0] == 0.0)
57 throw std::domain_error(
"Triangle::get_triangle_in_2d(): divide by zero.");
65 y.array() -=
x.array() *
x.array();
66 v_2d.topRightCorner(1, 1) =
x;
67 v_2d.bottomRightCorner(1, 1) = Eigen::sqrt(
y.array()).matrix();
89 throw std::domain_error(
"Triangle::local_coordinate_basis(): zero-length edge encountered.");
100 throw std::domain_error(
"Triangle::local_coordinate_basis(): zero-division encountered.");
103 if constexpr (
dim == 3)
104 uvw.col(2) = normal_;
110template <u
int8_t dim>
120 d = normal_.transpose() *
r_diff;
128template <u
int8_t dim>
140template <u
int8_t dim>
155 throw std::domain_error(
"Triangle::barycentric_coords(): divide by zero.");
171template <u
int8_t dim>
174 Float tol = TRIANGLE_DEFAULT_TOL * shortest_edge_length();
178 if (
val > tol &&
val - 1 < -tol)
185 if (std::abs(
val) < tol)
192 if (std::abs(
val - 1) < tol)
240template <u
int8_t dim>
248 if (
edge.point_on_edge(
r, tol))
254 p.col(0) = v_.col(0);
255 p.col(1) = v_.col(1);
262 p.col(0) = v_.col(1);
263 p.col(1) = v_.col(2);
270 p.col(0) = v_.col(2);
271 p.col(1) = v_.col(0);
286template <u
int8_t dim>
291 if constexpr (
dim == 2)
293 area = 0.5 * std::abs(v(0, 0) * (v(1, 1) - v(1, 2)) -
294 v(1, 0) * (v(0, 1) - v(0, 2)) +
295 (v(0, 1) * v(1, 2) - v(1, 1) * v(0, 2)));
297 else if constexpr (
dim == 3)
299 area = ((v.col(1) - v.col(0)).
cross(v.col(2) - v.col(0))).norm() / 2.0;
306template <u
int8_t dim>
309 if constexpr (
dim == 2)
310 return {0.0, 0.0, 1.0};
311 else if constexpr (
dim == 3)
Triangle< 3 > to_3d(const Float z=0.0) const
Adds a 0-valued third dimension if this Triangle is in 2D, otherwise just returns a copy of this Tria...
void get_plane_projection(EigMatNX< Float, dim > &r_proj, EigRowVec< Float > &d, ConstEigRef< EigMatNX< Float, 3 > > r, uint8_t ref_idx=0) const
Returns the projection of given points on to the triangle's plane, along with the normal distance to ...
EigMatMN< Float, dim, dim > local_coordinate_basis() const
Returns the unit vectors of a local coordinate system, defined in the global system,...
Float area() const
Returns the area of this Triangle.
EigColVecN< Float, 3 > normal() const
Returns the unit normal vector for this Triangle.
static Triangle< dim > reference_triangle()
Returns a reference triangle in the specified dimension.
void set_v(ConstEigRef< EigMatMN< Float, dim, 3 > > v, EigRowVecN< Float, 3 > edge_polarities=EigRowVecN< Float, 3 >::Constant(1, 3, 1))
Sets the vertices of this Triangle.
EigMatNX< Float, 3 > barycentric_coords(ConstEigRef< EigMatNX< Float, dim > > p) const
Returns barycentric coordinates of given points lying in the Triangle's plane.
Triangle< 2 > to_2d() const
Returns an equivalent triangle with coordinates in a local 2D system, with the local origin at this t...
bool point_in_triangle(ConstEigRef< EigColVecN< Float, dim > > r, const Float tol=TRIANGLE_DEFAULT_TOL) const
Checks whether a given point is inside the triangle, inclusive of edges and vertices.
EigRowVec< uint8_t > projection_loc(ConstEigRef< EigMatNX< Float, 3 > > r) const
Returns flags that indicate whether the given points project inside or outside the triangle,...
const Eigen::Ref< const EigObj > ConstEigRef
Read-only reference to an Eigen object.
Eigen::Matrix< T, 1, Eigen::Dynamic > EigRowVec
Dynamic-size row vector containing type T.
Eigen::Matrix< T, M, N > EigMatMN
Fixed-size matrix with M rows and N columns containing type T.
double Float
Floating point number.
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Eigen::Matrix< T, N, Eigen::Dynamic > EigMatNX
Fixed-height matrix with N rows containing type T.
Primary namespace for the OpenBEM library.