|
@@ -11,55 +11,55 @@
|
|
|
|
|
|
template<typename DerivedSource, typename DerivedDir>
|
|
|
IGL_INLINE bool igl::segments_intersect(
|
|
|
- const Eigen::PlainObjectBase <DerivedSource> &p,
|
|
|
- const Eigen::PlainObjectBase <DerivedDir> &r,
|
|
|
- const Eigen::PlainObjectBase <DerivedSource> &q,
|
|
|
- const Eigen::PlainObjectBase <DerivedDir> &s,
|
|
|
- double &a_t,
|
|
|
- double &a_u,
|
|
|
- double eps
|
|
|
+ const Eigen::PlainObjectBase <DerivedSource> &p,
|
|
|
+ const Eigen::PlainObjectBase <DerivedDir> &r,
|
|
|
+ const Eigen::PlainObjectBase <DerivedSource> &q,
|
|
|
+ const Eigen::PlainObjectBase <DerivedDir> &s,
|
|
|
+ double &a_t,
|
|
|
+ double &a_u,
|
|
|
+ double eps
|
|
|
)
|
|
|
{
|
|
|
- // http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
|
|
|
- // Search intersection between two segments
|
|
|
- // p + t*r : t \in [0,1]
|
|
|
- // q + u*s : u \in [0,1]
|
|
|
+ // http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
|
|
|
+ // Search intersection between two segments
|
|
|
+ // p + t*r : t \in [0,1]
|
|
|
+ // q + u*s : u \in [0,1]
|
|
|
|
|
|
- // p + t * r = q + u * s // x s
|
|
|
- // t(r x s) = (q - p) x s
|
|
|
- // t = (q - p) x s / (r x s)
|
|
|
+ // p + t * r = q + u * s // x s
|
|
|
+ // t(r x s) = (q - p) x s
|
|
|
+ // t = (q - p) x s / (r x s)
|
|
|
|
|
|
- // (r x s) ~ 0 --> directions are parallel, they will never cross
|
|
|
- Eigen::RowVector3d rxs = r.cross(s);
|
|
|
- if (rxs.norm() <= eps)
|
|
|
- return false;
|
|
|
+ // (r x s) ~ 0 --> directions are parallel, they will never cross
|
|
|
+ Eigen::RowVector3d rxs = r.cross(s);
|
|
|
+ if (rxs.norm() <= eps)
|
|
|
+ return false;
|
|
|
|
|
|
- int sign;
|
|
|
+ int sign;
|
|
|
|
|
|
- double u;
|
|
|
- // u = (q − p) × r / (r × s)
|
|
|
- Eigen::RowVector3d u1 = (q - p).cross(r);
|
|
|
- sign = ((u1.dot(rxs)) > 0) ? 1 : -1;
|
|
|
- u = u1.norm() / rxs.norm();
|
|
|
- u = u * sign;
|
|
|
+ double u;
|
|
|
+ // u = (q − p) × r / (r × s)
|
|
|
+ Eigen::RowVector3d u1 = (q - p).cross(r);
|
|
|
+ sign = ((u1.dot(rxs)) > 0) ? 1 : -1;
|
|
|
+ u = u1.norm() / rxs.norm();
|
|
|
+ u = u * sign;
|
|
|
|
|
|
- if ((u - 1.) > eps || u < -eps)
|
|
|
- return false;
|
|
|
+ double t;
|
|
|
+ // t = (q - p) x s / (r x s)
|
|
|
+ Eigen::RowVector3d t1 = (q - p).cross(s);
|
|
|
+ sign = ((t1.dot(rxs)) > 0) ? 1 : -1;
|
|
|
+ t = t1.norm() / rxs.norm();
|
|
|
+ t = t * sign;
|
|
|
|
|
|
- double t;
|
|
|
- // t = (q - p) x s / (r x s)
|
|
|
- Eigen::RowVector3d t1 = (q - p).cross(s);
|
|
|
- sign = ((t1.dot(rxs)) > 0) ? 1 : -1;
|
|
|
- t = t1.norm() / rxs.norm();
|
|
|
- t = t * sign;
|
|
|
+ a_t = t;
|
|
|
+ a_u = u;
|
|
|
|
|
|
- if (t < -eps || fabs(t) < eps)
|
|
|
- return false;
|
|
|
+ if ((u - 1.) > eps || u < -eps)
|
|
|
+ return false;
|
|
|
|
|
|
- a_t = t;
|
|
|
- a_u = u;
|
|
|
+ if ((t - 1.) > eps || t < -eps)
|
|
|
+ return false;
|
|
|
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
};
|
|
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|