1 #ifndef GEOMETRY_HPP_INCLUDED
2 #define GEOMETRY_HPP_INCLUDED
5 #include <Eigen/Geometry>
16 Eigen::Vector3d
const & b,
17 Eigen::Vector3d
const & c,
18 Eigen::Vector3d
const & d) {
19 return std::abs((a-d).dot((b-d).cross(c-d)))/6.;
24 Eigen::Vector3d
const &x2,
25 Eigen::Vector3d
const &x3) {
26 double a = (x1 - x2).squaredNorm();
27 double b = (x1 - x3).squaredNorm();
28 double c = (x2 - x3).squaredNorm();
30 return std::sqrt((a+b+c)*(a+b+c) - 2.*(a*a+b*b+c*c))*0.25;
34 Eigen::Vector2d
const &x2,
35 Eigen::Vector2d
const &x3) {
36 return std::abs((x1(0)-x3(0))*(x2(1)-x1(1)) - (x1(0)-x2(0))*(x3(1)-x1(1)))*0.5;
43 for (
size_t i = 0; i < vl.size(); ++i) {
44 for (
size_t j = 0; j < vl.size(); ++j) {
45 diam = std::max(diam,(vl[i]-vl[j]).squaredNorm());
48 return std::sqrt(diam);
53 template<
size_t dimension,
size_t d>
54 Eigen::Matrix<double,dimension,d>
tangent_space(std::vector<Eigen::Vector<double,dimension>>
const & vl) {
55 assert(vl.size() > d);
57 Eigen::Matrix<double,dimension,d> rv;
58 rv.col(0) = (vl[1]-vl[0]).normalise();
60 for (
size_t j = 1; j < vl.size(); ++j) {
61 Eigen::Vector<double,dimension> tmp = vl[j]-vl[0];
62 for (
size_t i = 0; i < nb_filled; ++i) {
63 double dotv = tmp.dot(rv.col(i));
64 tmp = tmp - dotv*rv.col(i);
66 if (tmp.squaredNorm() > 1e-10) {
67 rv.col(nb_filled) = tmp.normalise();
69 if (nb_filled == d)
return rv;
79 Eigen::Vector<double,d> mid = S[d];
80 for (
size_t i = 0; i < d; ++i) {
90 constexpr
double esp = 1e-10;
91 Eigen::Matrix<double,d,d> T;
92 for (
size_t i = 0; i < d; ++i) {
93 for (
size_t j = 0; j < d; ++j) {
94 T(i,j) = S[j](i) - S[d](i);
97 Eigen::Vector<double,d> L = T.partialPivLu().solve(x - S[d]);
99 for (
size_t i = 0; i < d; ++i) {
100 if (L(i) < -esp || L(i) > 1. + esp)
return false;
103 return p_sum < 1. + esp && p_sum > -esp;
Reference for signature of the functions that must be provided alongside the mesh.
Definition: geometry.hpp:12
Eigen::Matrix< double, dimension, d > tangent_space(std::vector< Eigen::Vector< double, dimension >> const &vl)
Compute a possible basis for the tangent space from a vector of vertices.
Definition: geometry.hpp:54
double volume_tetrahedron(Eigen::Vector3d const &a, Eigen::Vector3d const &b, Eigen::Vector3d const &c, Eigen::Vector3d const &d)
Volume of a tetrahedron in 3D given by its 4 vertices.
Definition: geometry.hpp:15
double volume_triangle(Eigen::Vector3d const &x1, Eigen::Vector3d const &x2, Eigen::Vector3d const &x3)
Area of a triangle in 3D given by its 3 vertices.
Definition: geometry.hpp:23
double diameter(std::vector< T > const &vl)
Diameter of the convex hull of a vector of vertices in ND.
Definition: geometry.hpp:41
bool inside(Eigen::Vector< double, d > const &x, Simplex< d > const &S)
Is a vector x inside a simplex S.
Definition: geometry.hpp:88
Eigen::Vector< double, d > middleSimplex(Simplex< d > const &S)
Compute the centroid of a simplex S.
Definition: geometry.hpp:77
std::array< Eigen::Vector< double, d >, d+1 > Simplex
Array of d+1 points of .
Definition: definitions.hpp:16