Could not get intersection for two overlapping circles

Code in question:

#include <cstdio>

#include <Geom2d_Circle.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2dAPI_InterCurveCurve.hxx>
#include <gp_Circ2d.hxx>


gp_Ax2d make_axis2d(Standard_Real x, Standard_Real y) {
    return gp_Ax2d(gp_Pnt2d(x, y), gp_Dir2d(1, 0));
}

int main() {
    gp_Circ2d gc1 = gp_Circ2d(make_axis2d(0, 0), 10);
    gp_Circ2d gc2 = gp_Circ2d(make_axis2d(5, 0), 10);
    gp_Circ2d gc3 = gp_Circ2d(make_axis2d(10, 0), 10);

    Handle(Geom2d_Circle) c1 = new Geom2d_Circle(gc1);
    Handle(Geom2d_Circle) c2 = new Geom2d_Circle(gc2);
    Handle(Geom2d_Circle) c3 = new Geom2d_Circle(gc3);

    Geom2dAPI_InterCurveCurve Intersector1(c1, c2, 10e-6); 
    Standard_Integer N = Intersector1.NbPoints();
    printf("Intersections c1 vs c2: %i\n", N);
    for (int i=1; i<=N; i++){
        auto pt = Intersector1.Point(i);
        printf("  %f %f\n", pt.X(), pt.Y());
    }

    Geom2dAPI_InterCurveCurve Intersector2(c1, c3, 10e-6); 
    N = Intersector2.NbPoints();
    printf("Intersections c1 vs c3: %i\n", N);
    for (int i=1; i<=N; i++){
        auto pt = Intersector2.Point(i);
        printf("  %f %f\n", pt.X(), pt.Y());
    }
}

Output:

Intersections c1 vs c2: 0
Intersections c1 vs c3: 2
  5.000000 -8.660254
  5.000000 8.660254

All circles are overlapping, radius 10, centers are on Y axis, with Xs: 0, 5, 10. But I get intersection points only for c1 and c3. I've tried 7.7 and 7.8 lib versions. What am I missing?

Thomas Anderson's picture

print out Geom2dAPI_InterCurveCurve::NbSegments() along with your point count and run. Then change your intersection tolerance to 0.0 and run. The closer the circles are to coincidental or tangent combined with your tolerance will affect whether you get points or curve segments.

baverman's picture

Oh, wow. Zero tolerance did the trick. Thank you! It's quite non intuitive that visibly circles are clearly intersecting but 10e-6 tolerance is too big. Good to know!