-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SofaBaseTopology] add intersection methods #2131
Changes from all commits
f3079c7
5108363
8d913f6
421f937
e7f2c3a
2e85825
af37bf1
ec51d19
d4a3ae7
d5cb454
d2429f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -899,5 +899,50 @@ void EdgeSetGeometryAlgorithms<DataTypes>::initPointAdded(PointID index, const c | |
} | ||
} | ||
|
||
template<class DataTypes> | ||
bool EdgeSetGeometryAlgorithms<DataTypes>::computeEdgeSegmentIntersection(EdgeID edgeID, | ||
const sofa::defaulttype::Vec<3, Real>& a, | ||
const sofa::defaulttype::Vec<3, Real>& b, | ||
Real &baryCoef) | ||
{ | ||
const double EPS = 1e-05; | ||
bool is_intersect = false; | ||
|
||
const Edge& e = this->m_topology->getEdge(edgeID); | ||
const VecCoord& p = (this->object->read(core::ConstVecCoordId::position())->getValue()); | ||
const typename DataTypes::Coord& c0 = p[e[0]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a requirement but using 'auto' is more readable |
||
const typename DataTypes::Coord& c1 = p[e[1]]; | ||
|
||
sofa::defaulttype::Vec<3, Real> p0{ c0[0],c0[1],c0[2] }; | ||
sofa::defaulttype::Vec<3, Real> p1{ c1[0],c1[1],c1[2] }; | ||
sofa::defaulttype::Vec<3, Real> pa{ a[0],a[1],a[2] }; | ||
sofa::defaulttype::Vec<3, Real> pb{ b[0],b[1],b[2] }; | ||
|
||
sofa::defaulttype::Vec<3, Real> v_0a = p0 - pa; | ||
sofa::defaulttype::Vec<3, Real> v_ba = pb - pa; | ||
sofa::defaulttype::Vec<3, Real> v_10 = p1 - p0; | ||
|
||
Real d0aba, dba10, d0a10, dbaba, d1010; | ||
|
||
d0aba = v_0a * v_ba; | ||
dba10 = v_ba * v_ba; | ||
d0a10 = v_0a * v_10; | ||
dbaba = v_ba * v_ba; | ||
d1010 = v_10 * v_10; | ||
|
||
Real deno, num; | ||
deno = d1010 * dbaba - dba10 * dba10; | ||
if (!abs(deno) <= EPS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect a logic issue here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EdgeSetGeometryAlgorithms.inl:935:9: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses] |
||
{ | ||
num = d0aba * dba10 - d0a10 * dbaba; | ||
|
||
//baryCoef= (d0aba + dba10 * (num / deno)) / dbaba; | ||
baryCoef = num / deno; | ||
//if (baryCoef >= 0.0 && baryCoef <= 1.0) | ||
is_intersect = true; | ||
} | ||
return is_intersect; | ||
} | ||
|
||
|
||
} //namespace sofa::component::topology |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the point of the PR as it is also done in the existing code but it would be better to use Real instead of double.