15#include <lagrange/MeshTrait.h>
22template <
typename Scalar,
int _Rows,
int _Cols>
24 const Eigen::Matrix<Scalar, _Rows, _Cols>& v1,
25 const Eigen::Matrix<Scalar, _Rows, _Cols>& v2)
27 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
28 Scalar dot = v1.dot(v2);
29 if (dot < -1)
return Scalar(-1.0);
30 if (dot > 1)
return Scalar(1.0);
35template <
typename Scalar,
int _Rows,
int _Cols>
37 const Eigen::Matrix<Scalar, _Rows, _Cols>& v1,
38 const Eigen::Matrix<Scalar, _Rows, _Cols>& v2)
40 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
41 return std::atan2(v1.cross(v2).norm(), v1.dot(v2));
47template <
typename Scalar,
int _Rows,
int _Cols>
49 const Eigen::Matrix<Scalar, _Rows, _Cols>& v1,
50 const Eigen::Matrix<Scalar, _Rows, _Cols>& v2)
52 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
53 return v1.dot(v2) * v2;
58template <
typename Scalar,
int _Rows,
int _Cols>
60 const Eigen::Matrix<Scalar, _Rows, _Cols>& v,
61 const Eigen::Matrix<Scalar, _Rows, _Cols>& n)
63 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
69template <
typename Scalar,
int _Rows,
int _Cols>
71 const Eigen::Matrix<Scalar, _Rows, _Cols>& v1,
72 const Eigen::Matrix<Scalar, _Rows, _Cols>& v2,
73 const Eigen::Matrix<Scalar, _Rows, _Cols>& n)
75 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
76 const Eigen::Matrix<Scalar, _Rows, _Cols> proj1 =
project_on_plane(v1, n).stableNormalized();
77 const Eigen::Matrix<Scalar, _Rows, _Cols> proj2 =
project_on_plane(v2, n).stableNormalized();
83template <
typename Scalar,
int _Rows,
int _Cols>
85 const Eigen::Matrix<Scalar, _Rows, _Cols>& v1,
86 const Eigen::Matrix<Scalar, _Rows, _Cols>& v2,
87 const Eigen::Matrix<Scalar, _Rows, _Cols>& n)
89 static_assert((_Rows == 1 && _Cols == 3) || (_Rows == 3 && _Cols == 1),
"");
92 return std::atan2(proj1.cross(proj2).norm(), proj1.dot(proj2));
103template <
typename MeshType>
107 return mesh.get_vertices().row(v2) - mesh.get_vertices().row(v1);
119template <
typename Scalar>
121 const Eigen::Matrix<Scalar, 3, 1>& x,
122 Eigen::Matrix<Scalar, 3, 1>& y,
123 Eigen::Matrix<Scalar, 3, 1>& z)
126 x.array().abs().minCoeff(&imin);
127 Eigen::Matrix<Scalar, 3, 1> u;
128 for (
int i = 0, s = -1; i < 3; ++i) {
140 z = x.cross(u).stableNormalized();
141 y = z.cross(x).stableNormalized();
Main namespace for Lagrange.
Definition: AABBIGL.h:30
void orthogonal_frame(const Eigen::Matrix< Scalar, 3, 1 > &x, Eigen::Matrix< Scalar, 3, 1 > &y, Eigen::Matrix< Scalar, 3, 1 > &z)
Build an orthogonal frame given a single vector.
Definition: geometry3d.h:120
Scalar projected_cos_angle_between(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2, const Eigen::Matrix< Scalar, _Rows, _Cols > &n)
Returns the angle between the vectors v1 and v2 projected on the plane defined by its normal n.
Definition: geometry3d.h:70
Scalar projected_angle_between(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2, const Eigen::Matrix< Scalar, _Rows, _Cols > &n)
Returns the angle between the vectors v1 and v2 projected on the plane defined by its normal n.
Definition: geometry3d.h:84
Eigen::Matrix< Scalar, _Rows, _Cols > project_on_plane(const Eigen::Matrix< Scalar, _Rows, _Cols > &v, const Eigen::Matrix< Scalar, _Rows, _Cols > &n)
Project the vector on the plane defined by its normal n.
Definition: geometry3d.h:59
auto vector_between(const MeshType &mesh, typename MeshType::Index v1, typename MeshType::Index v2)
Returns the vector from v1 to v2.
Definition: geometry3d.h:104
Eigen::Matrix< Scalar, _Rows, _Cols > project_on_line(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2)
Project the vector v1 on the line defined by its vector v2.
Definition: geometry3d.h:48
Scalar cos_angle_between(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2)
Returns the cosine of the angle between two 3d vectors.
Definition: geometry3d.h:23
Scalar angle_between(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2)
Returns the angle between two 3d vectors.
Definition: geometry3d.h:36
MeshTrait class provide compiler check for different mesh types.
Definition: MeshTrait.h:108