|
1 | 1 | #include "edge_edge.hpp" |
2 | 2 |
|
3 | 3 | #include <ipc/distance/edge_edge.hpp> |
| 4 | +#include <ipc/tangent/closest_point.hpp> |
4 | 5 |
|
5 | 6 | namespace ipc { |
6 | 7 |
|
@@ -36,6 +37,63 @@ EdgeEdgeCandidate::compute_distance_hessian(const VectorMax12d& positions) const |
36 | 37 | positions.tail<3>(), known_dtype()); |
37 | 38 | } |
38 | 39 |
|
| 40 | +VectorMax4d |
| 41 | +EdgeEdgeCandidate::compute_coefficients(const VectorMax12d& positions) const |
| 42 | +{ |
| 43 | + assert(positions.size() == 12); |
| 44 | + const Eigen::Ref<const Eigen::Vector3d> ea0 = positions.head<3>(); |
| 45 | + const Eigen::Ref<const Eigen::Vector3d> ea1 = positions.segment<3>(3); |
| 46 | + const Eigen::Ref<const Eigen::Vector3d> eb0 = positions.segment<3>(6); |
| 47 | + const Eigen::Ref<const Eigen::Vector3d> eb1 = positions.tail<3>(); |
| 48 | + |
| 49 | + // Project the point inside the triangle |
| 50 | + auto dtype = known_dtype(); |
| 51 | + if (dtype == EdgeEdgeDistanceType::AUTO) { |
| 52 | + dtype = edge_edge_distance_type(ea0, ea1, eb0, eb1); |
| 53 | + } |
| 54 | + |
| 55 | + VectorMax4d coeffs(4); |
| 56 | + switch (dtype) { |
| 57 | + case EdgeEdgeDistanceType::EA0_EB0: |
| 58 | + coeffs << 1.0, 0.0, -1.0, 0.0; |
| 59 | + break; |
| 60 | + case EdgeEdgeDistanceType::EA0_EB1: |
| 61 | + coeffs << 1.0, 0.0, 0.0, -1.0; |
| 62 | + break; |
| 63 | + case EdgeEdgeDistanceType::EA1_EB0: |
| 64 | + coeffs << 0.0, 1.0, -1.0, 0.0; |
| 65 | + break; |
| 66 | + case EdgeEdgeDistanceType::EA1_EB1: |
| 67 | + coeffs << 0.0, 1.0, 0.0, -1.0; |
| 68 | + break; |
| 69 | + case EdgeEdgeDistanceType::EA_EB0: { |
| 70 | + const double alpha = point_edge_closest_point(eb0, ea0, ea1); |
| 71 | + coeffs << 1.0 - alpha, alpha, -1.0, 0; |
| 72 | + } break; |
| 73 | + case EdgeEdgeDistanceType::EA_EB1: { |
| 74 | + const double alpha = point_edge_closest_point(eb1, ea0, ea1); |
| 75 | + coeffs << 1.0 - alpha, alpha, 0, -1.0; |
| 76 | + } break; |
| 77 | + case EdgeEdgeDistanceType::EA0_EB: { |
| 78 | + const double alpha = point_edge_closest_point(ea0, eb0, eb1); |
| 79 | + coeffs << 1.0, 0, -1.0 + alpha, -alpha; |
| 80 | + } break; |
| 81 | + case EdgeEdgeDistanceType::EA1_EB: { |
| 82 | + const double alpha = point_edge_closest_point(ea1, eb0, eb1); |
| 83 | + coeffs << 0, 1.0, -1.0 + alpha, -alpha; |
| 84 | + } break; |
| 85 | + case EdgeEdgeDistanceType::EA_EB: { |
| 86 | + const Eigen::Vector2d ab = edge_edge_closest_point(ea0, ea1, eb0, eb1); |
| 87 | + coeffs << 1.0 - ab[0], ab[0], -1.0 + ab[1], -ab[1]; |
| 88 | + } break; |
| 89 | + default: |
| 90 | + assert(false); |
| 91 | + break; |
| 92 | + } |
| 93 | + |
| 94 | + return coeffs; |
| 95 | +} |
| 96 | + |
39 | 97 | bool EdgeEdgeCandidate::ccd( |
40 | 98 | const VectorMax12d& vertices_t0, |
41 | 99 | const VectorMax12d& vertices_t1, |
|
0 commit comments