18#ifndef GEOM_TRIANGLE_H
19#define GEOM_TRIANGLE_H
32const Float TRIANGLE_DEFAULT_TOL = 1.0e-6;
120 throw std::out_of_range(
"Triangle::v(): vertex index out of bounds.");
131 return edge_polarities_;
143 throw std::out_of_range(
"Triangle::edge_polarities(): edge index out of bounds.");
144 return edge_polarities_[
idx];
153 set_v(v_.rowwise().reverse(), edge_polarities_.reverse());
179 {
return centroid_; };
190 len += (v_.col(
ii) - v_.col((
ii + 1) % 3)).norm();
263 lengths[
ii] = (v_.col((
ii + 1) % 3) - v_.col((
ii) % 3)).norm();
276 assert(
result < 3 &&
"Triangle::longest_edge(): Result out of range.");
289 assert(
result < 3 &&
"Triangle::shortest_edge(): Result out of range.");
348 template <u
int8_t dim_out>
384 {
return v.rowwise().sum() / (
Float)3; };
Triangle primitive class.
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...
Float shortest_edge_length() const
Length of the shortest edge of this Triangle.
uint8_t shortest_edge_index() const
Returns the index associated with the shortest edge of this Triangle.
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 ...
Triangle()
Constructs a default reference Triangle object.
Float mean_edge_length() const
Returns the mean edge length of this Triangle.
static EigColVecN< Float, dim > centroid(ConstEigRef< EigMatMN< Float, dim, 3 > > v)
Computes the centroid of the triangle formed by the given vertices.
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 > edge_lengths() const
Returns the lengths of each edge of this Triangle.
const EigMatMN< Float, dim, 3 > & v() const
Returns the vertices of this Triangle.
Float longest_edge_length() const
Length of the longest edge of this Triangle.
Float edge_polarities(const uint8_t idx) const
Returns the edge polarity of this Triangle at a given index.
EigColVecN< Float, dim_out > map_points(ConstEigRef< EigColVecN< Float, dim > > points, const Triangle< dim_out > &tri_out) const
Performs an affine transform to map points lying in this triangle's plane to the output triangle's pl...
EigColVecN< Float, 3 > normal() const
Returns the unit normal vector for this Triangle.
uint8_t longest_edge_index() const
Returns the index associated with the longest edge of this Triangle.
const EigRowVecN< Float, 3 > & edge_polarities() const
Returns the edge polarities of this Triangle.
static Triangle< dim > reference_triangle()
Returns a reference triangle in the specified dimension.
EigColVecN< Float, dim > v(const uint8_t idx) const
Returns the vertex of this Triangle at a given index.
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.
EigColVecN< Float, dim > local_origin() const
Returns the local origin of this Triangle in the global coordinate system. The local origin is just t...
EigMatNX< Float, 3 > barycentric_coords(ConstEigRef< EigMatNX< Float, dim > > p) const
Returns barycentric coordinates of given points lying in the Triangle's plane.
void reverse()
Reverses the orientation of this Triangle.
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.
Triangle(std::array< EigColVecN< Float, dim >, 3 > v_array, EigRowVecN< Float, 3 > edge_polarities=EigRowVecN< Float, 3 >::Constant(1, 3, 1))
Constructs a Triangle with given vertices.
EigColVecN< Float, dim > centroid() const
Returns the centroid of this Triangle.
Triangle(ConstEigRef< EigMatMN< Float, dim, 3 > > v, EigRowVecN< Float, 3 > edge_polarities=EigRowVecN< Float, 3 >::Constant(1, 3, 1))
Constructs a Triangle with given 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.
double Float
Floating point number.
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Eigen::Matrix< T, 1, N > EigRowVecN
Fixed-size row vector of size N containing type T.
Primary namespace for the OpenBEM library.