Added TriangleTriangleIntersect2D function
This commit is contained in:
parent
cf619d282b
commit
ed6221e993
vcg/space
|
@ -216,6 +216,44 @@ template<class SCALAR_TYPE>
|
|||
//return((Convex(p,p0,p1))&&(Convex(p,p1,p2))&&(Convex(p,p2,p0)));
|
||||
}
|
||||
|
||||
template<class ScalarType>
|
||||
bool TriangleTriangleIntersect2D(const vcg::Triangle2<ScalarType> &tr0,
|
||||
const vcg::Triangle2<ScalarType> &tr1)
|
||||
{
|
||||
///test BBox Intersection
|
||||
vcg::Box2<ScalarType> bbtr0;
|
||||
bbtr0.Add(tr0.P(0));
|
||||
bbtr0.Add(tr0.P(1));
|
||||
bbtr0.Add(tr0.P(2));
|
||||
vcg::Box2<ScalarType> bbtr1;
|
||||
bbtr1.Add(tr1.P(0));
|
||||
bbtr1.Add(tr1.P(1));
|
||||
bbtr1.Add(tr1.P(2));
|
||||
if (!bbtr0.Collide(bbtr1)) return false;
|
||||
///test vertex in face
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
bool inside0=vcg::IsInsideTrianglePoint(tr0,tr1.P(i));
|
||||
bool inside1=vcg::IsInsideTrianglePoint(tr1,tr0.P(i));
|
||||
if (inside0 || inside1) return true;
|
||||
}
|
||||
///test segment
|
||||
///to segment intersection
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
for (int j=0;j<3;j++)
|
||||
{
|
||||
if (i>j) continue;
|
||||
vcg::Segment2<ScalarType> seg0=vcg::Segment2<ScalarType>(tr0.P(i),tr0.P((i+1)%3));
|
||||
vcg::Segment2<ScalarType> seg1=vcg::Segment2<ScalarType>(tr1.P(j),tr1.P((j+1)%3));
|
||||
vcg::Point2<ScalarType> p_inters;
|
||||
bool intersect=SegmentSegmentIntersection(seg0,seg1,p_inters);
|
||||
if (intersect) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//intersection between a circle and a line
|
||||
template<class ScalarType>
|
||||
inline bool CircleLineIntersection(const vcg::Line2<ScalarType> & line,
|
||||
|
|
Loading…
Reference in New Issue