17 const Eigen::Ref<const Eigen::Vector2d> &a,
18 const Eigen::Ref<const Eigen::Vector2d> &b,
19 const Eigen::Ref<const Eigen::Vector2d> &c,
20 const Eigen::Ref<const Eigen::Vector2d> &d,
21 Eigen::Ref<Eigen::Vector2d> &intersectionPoint)
24 double D = a(0) * (d(1) - c(1)) +
25 b(0) * (c(1) - d(1)) +
26 d(0) * (b(1) - a(1)) -
36 double s = (a(0) * (d(1) - c(1)) + c(0) * (a(1) - d(1)) + d(0) * (c(1) - a(1))) / D;
38 intersectionPoint = a + s * (b - a);
43 const Eigen::Vector3d &pointOnPlane,
44 const Eigen::Vector3d &planeNormal,
45 const Eigen::Vector3d &firstPointSegment,
46 const Eigen::Vector3d &secondPointSegment,
47 Eigen::Vector3d &intersectionPoint)
53 double d = pointOnPlane.dot(planeNormal);
64 Eigen::Vector3d segmentVec(secondPointSegment - firstPointSegment);
65 double nominator = d - firstPointSegment.dot(planeNormal);
66 double denominator = segmentVec.dot(planeNormal);
74 double t = nominator / denominator;
82 intersectionPoint = firstPointSegment + segmentVec * t;
94 const Eigen::VectorXd &a,
95 const Eigen::VectorXd &b,
96 const Eigen::VectorXd &c)
101 Eigen::Vector2d A = b;
103 Eigen::Vector2d B = c;
105 return 0.5 *
std::fabs(A(0) * B(1) - A(1) * B(0));
108 Eigen::Vector3d A = b;
110 Eigen::Vector3d B = c;
112 return 0.5 * A.cross(B).norm();
126 const Eigen::Vector3d &
vector,
127 int indexDimensionToRemove)
131 Eigen::Vector2d projectedVector;
133 for (
int dim = 0; dim < 3; dim++) {
134 if (indexDimensionToRemove == dim) {
137 projectedVector(reducedDim) =
vector(dim);
140 return projectedVector;
150 [](
const auto &v) { return v.size() == 2 || v.size() == 3; }),
151 "This only works in 2D or 3D.");
154 if (coords[0].size() == 3) {
156 Eigen::Vector3d coordOrigin;
157 coordOrigin = coords[0];
160 Eigen::Vector3d e_1 = coords[1] - coordOrigin;
161 Eigen::Vector3d e_2 = coords[2] - coordOrigin;
162 Eigen::Vector3d normalVector = e_1.cross(e_2);
165 "Non-planar quads are not supported. The vertex coordinates are: {}.", coords);
168 for (
int i = 0; i < 4; i++) {
169 Eigen::Vector3d coordinateDifference = coords[i] - coordOrigin;
170 coords[i][0] = e_1.dot(coordinateDifference);
171 coords[i][1] = e_2.dot(coordinateDifference);
172 coords[i][2] = normalVector.dot(coordinateDifference);
175 if (coords[0].size() == 2) {
176 Eigen::Vector2d coordOrigin;
177 coordOrigin = coords[0];
179 Eigen::Vector2d e_1 = coords[1] - coordOrigin;
180 Eigen::Vector2d e_2 = coords[2] - coordOrigin;
183 for (
int i = 0; i < 4; i++) {
184 Eigen::Vector2d coordinateDifference = coords[i] - coordOrigin;
185 coords[i][0] = e_1.dot(coordinateDifference);
186 coords[i][1] = e_2.dot(coordinateDifference);
197 int idLowestPoint = 0;
198 for (
int i = 1; i < 4; i++) {
199 if (coords[i][0] < coords[idLowestPoint][0]) {
206 int validVertexIDCounter = 0;
207 int currentVertex = idLowestPoint;
212 result.
vertexOrder[validVertexIDCounter] = currentVertex;
215 int nextVertex = (currentVertex + 1) % 4;
216 for (
int i = 0; i < 4; i++) {
217 double y1 = coords[currentVertex][1] - coords[nextVertex][1];
218 double y2 = coords[currentVertex][1] - coords[i][1];
219 double x1 = coords[currentVertex][0] - coords[nextVertex][0];
220 double x2 = coords[currentVertex][0] - coords[i][0];
221 double val = y2 * x1 - y1 * x2;
230 currentVertex = nextVertex;
231 validVertexIDCounter++;
232 }
while (currentVertex != idLowestPoint);
235 result.
convex = (validVertexIDCounter == 4);