-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNeedleOperations.cpp
More file actions
31 lines (24 loc) · 1.04 KB
/
NeedleOperations.cpp
File metadata and controls
31 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <sofa/collisionAlgorithm/operations/NeedleOperations.h>
namespace sofa::collisionAlgorithm::Operations::Needle
{
bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
const EdgeElement::SPtr& edge)
{
if (!edge)
{
msg_warning("Needle::PrunePointsAheadOfTip")
<< "Null element pointer in prunePointsUsingEdges; returning false";
return false;
}
const type::Vec3 edgeBase(edge->getP0()->getPosition());
const type::Vec3 tip(edge->getP1()->getPosition());
const type::Vec3 edgeDirection = tip - edgeBase;
if (couplingPts.empty()) return true;
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
// Positive dot product means the point is ahead of the tip
if (dot(tip2Pt, edgeDirection) > 0_sreal) couplingPts.pop_back();
return true;
}
int register_PrunePointsAheadOfTip_Edge =
PrunePointsAheadOfTip::register_func<EdgeElement>(&prunePointsUsingEdges);
} // namespace sofa::collisionAlgorithm::Operations::Needle