Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] How can i tell which is the intersection point and which is the endpoint of the curve ?

Subject: CGAL users discussion list

List archive

[cgal-discuss] How can i tell which is the intersection point and which is the endpoint of the curve ?


Chronological Thread 
  • From: chm <>
  • To:
  • Subject: [cgal-discuss] How can i tell which is the intersection point and which is the endpoint of the curve ?
  • Date: Thu, 21 Mar 2013 18:25:56 -0700 (PDT)

I'm intend to compute the intersection points of two curves with
CGAL::compute_intersection_points .
Sometimes the endpoints of the two curves may be intersections too, so I use
CGAL::compute_intersection_points to treat endpoints of curves as
intersection points too.
the problem is that the CGAL::compute_intersection_points will
treat every endpoints of the two curves as intersection points, so I have to
tell which is just an endpoint and which is both an endpoint and a
intersection point.
But the method PtInCurve I use doesn't work well, sometime It can
filter those endpoints away and left the intersection points but sometimes
it filter the intersections away....
someone help me , thank you !
I list some of my codes here !

typedef CGAL::Cartesian<CGAL::Quotient&lt;CGAL::MP_Float>> Kernel;

typedef Kernel::Circle_2
Circle_2;
typedef Kernel::Segment_2
Segment_2;
typedef Kernel::Line_2
Line_2;
typedef Kernel::Point_2
Point_2d;

typedef CGAL::Arr_circle_segment_traits_2<Kernel>
Traits_2;
typedef Traits_2::CoordNT
CoordNT;
typedef Traits_2::Point_2
Point_2;
typedef Traits_2::Curve_2
Curve_2;

// test whether two curves intersect or not
bool TestCurvesIntersetion(Curve_2 cur1, Curve_2 cur2, std::pair<double,
double>& interSectPoint)
{
std::vector<Point_2> pts;
std::vector<Curve_2> curves;

curves.push_back (cur1);
curves.push_back (cur2);

// Compute all intersection points.
CGAL::compute_intersection_points (curves.begin(), curves.end(),
std::back_inserter (pts), true);

if (!pts.empty())
{
// we need to kick the endpoints out
for (int i = 0; i < pts.size(); i++)
{
Point_2& pt = pts[i];
interSectPoint.first = to_double(pt.x());
interSectPoint.second = to_double(pt.y());

bool ptInCur1 =
PtInCurve(cur1,interSectPoint.first,interSectPoint.second);
bool ptInCur2 =
PtInCurve(cur2,interSectPoint.first,interSectPoint.second);

// if the point lies in both two curves then it is
an intersection point
if(ptInCur1&& ptInCur2)
{
return true;
}
}
}

return false;
}

// if the intersection point lies in both curves then it is a intersection
point else it is just an endpoint
bool PtInCurve(Curve_2 cur1, double dx,double dy)

{
/*! Check if the arc is linear. */
Point_2d pt2(dx,dy);
if(cur1.is_linear())
{
Line_2 line = cur1.supporting_line();

// here is the problem : sometimes the intersection point
doesn't lie in both two curves.....
bool bRet = line.has_on(pt2);
return bRet;
}
else
{
Circle_2 cir= cur1.supporting_circle();
bool bRet= cir.has_on_boundary(pt2);
return bRet;
}
}



--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/How-can-i-tell-which-is-the-intersection-point-and-which-is-the-endpoint-of-the-curve-tp4657004.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page