Skip to Content.
Sympa Menu

cgal-discuss - Re: [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

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


Chronological Thread 
  • From: Efi Fogel <>
  • To:
  • Subject: Re: [cgal-discuss] How can i tell which is the intersection point and which is the endpoint of the curve ?
  • Date: Wed, 27 Mar 2013 12:04:28 +0200

Why do you use an inexact number type (i.e., double) to determine whether a point lies on a curve?
Beside, I see that for an exact number type you use CGAL::Quotient<CGAL::MP_Float>>. If possible, I suggest that you use Gmpq instead.



On Fri, Mar 22, 2013 at 3:25 AM, chm <> wrote:
         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<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.

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss





--
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/





Archive powered by MHonArc 2.6.18.

Top of Page