MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030217Community[OCCT] OCCT:Modeling Algorithmspublic2018-10-08 16:582018-10-08 18:21
Reporterabdullah 
Assigned Toifv 
PrioritynormalSeveritymajor 
StatusassignedResolutionopen 
PlatformUbuntu 18.04.1 LTS 64-bitOSOS Version
Product Version[OCCT] 7.3.0 
Target Version[OCCT] 7.4.0*Fixed in Version 
Summary0030217: Intersection between a circle and a line not detected WHEN TANGENT
DescriptionIntersection between a circle and a line not detected WHEN TANGENT when using either Geom2dAPI_InterCurveCurve or GeomAPI_ExtremaCurveCurve.

For a more visual view, see picture here:
https://forum.freecadweb.org/viewtopic.php?f=10&t=31371 [^]

Basically:
1. If a line is tangential to a circle, the endpoint of the line at 1e-12 of the circumference, when executing either Geom2dAPI_InterCurveCurve or GeomAPI_ExtremaCurveCurve with 1e-8 tolerance does not detect any intersection/extrema.

2. If the line is NOT tangential (just by changing the startpoint of the line to another position), same distance of 1e-12 between endpoint and circumference, same tolerance, both algorithms detect the intersection/extrema.

Below a straightforward c++ code, compilable under ubuntu with:
g++ intersector.cpp -I/usr/include/occt -L/usr/lib/x86_64-linux-gnu -lTKG3d -lTKernel -lTKMath -lTKGeomBase -lTKGeomAlgo -o intersector

In additional information you can find the output of this c++ program in my computer.
Steps To Reproduce############
# Draw script
############

# 2D case
2ddrseg s2 -80.461134694338 53.07587187722 -31.501464018476 67.029737602069
circle c2 -18.339655323916 20.849340929486 48.019394466707
2dintersect c2 s2 -tol 1e-8

# 3D case
drseg s -80.461134694338 53.07587187722 0.0 -31.501464018476 67.029737602069 0.0
circle c -18.339655323916 20.849340929486 0.0 48.019394466707
extrema c s


//////////////
// C++ code
//////////////

# include <Geom_Circle.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Line.hxx>
# include <Geom_Plane.hxx>

# include <GC_MakeCircle.hxx>
# include <GC_MakeSegment.hxx>


# include <gp.hxx>
# include <gp_Ax2.hxx>
# include <gp_Pnt.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx>

# include <GeomAPI.hxx>
# include <Geom2d_Curve.hxx>
# include <Geom2dAPI_InterCurveCurve.hxx>
# include <GeomAPI_ExtremaCurveCurve.hxx>

int main()
{

    double precision = 1.0e-8;
    // A line segment
    gp_Pnt p1(-80.461134694338, 53.07587187722, 0.0), p2(-31.501464018476, 67.029737602069, 0.0);
    GC_MakeSegment ms(p1, p2);
    Handle(Geom_TrimmedCurve) tc_line = ms.Value();

    // A circunference
    gp_Pnt center(-18.339655323916, 20.849340929486, 0.0);
    double radius = 48.019394466707;
    gp_Dir norm(0,0,1);

    gp_Ax2 xdir(center, norm);

    GC_MakeCircle mc(xdir, radius);

    Handle(Geom_Circle) circle = mc.Value();

    // NOTE: The line is made to be substantially tangent to the circunference
    double distance_endpoint_linesegment_to_center_cirncunf = center.Distance(p2);
    printf("SETUP 1:\n");
    printf("========\n");
    printf("Description: Circle with touching tangential line\n\n");
    printf("Distance from endpoint of line segment to center circunf: %f\n", distance_endpoint_linesegment_to_center_cirncunf);
    printf("Distance from circunference to endpoint of line segment: %.10e\n\n", distance_endpoint_linesegment_to_center_cirncunf - radius);

    // Algorithm1: 2D intersection with Geom2dAPI_InterCurveCurve
    gp_Pln plane(gp_Pnt(0,0,0),gp_Dir(0,0,1));
    Handle(Geom2d_Curve) circle2dCurve;
    circle2dCurve = GeomAPI::To2d(circle, plane);

    Handle(Geom2d_Curve) line2dCurve;
    line2dCurve = GeomAPI::To2d(tc_line, plane);


    Geom2dAPI_InterCurveCurve Intersector2d;

    printf("Algorithm: Geom2dAPI_InterCurveCurve - precision/tolerance: %.10g\n",precision);

    Intersector2d.Init(circle2dCurve, line2dCurve, 1.0e-8);
    printf("\tGeom2dAPI_InterCurveCurve - NbPoints: %d\n", Intersector2d.NbPoints());
    printf("\tGeom2dAPI_InterCurveCurve - NbSegments: %d\n", Intersector2d.NbSegments());

    for (int i=1; i <= Intersector2d.NbPoints(); i++) {
        gp_Pnt2d p = Intersector2d.Point(i);
        printf("\t%d: (%f,%f,0)\n",i,p.X(),p.Y());
    }

    // Algorithm2: GeomAPI_ExtremaCurveCurve
    printf("\nAlgorithm: GeomAPI_ExtremaCurveCurve - precision/tolerance: %.10g\n",precision);

    GeomAPI_ExtremaCurveCurve Intersector3d(circle, tc_line);

    printf("\tGeomAPI_ExtremaCurveCurve - NbExtrema: %d\n", Intersector3d.NbExtrema());

    // Setup 2: non tangencial line, same endpoint
    gp_Pnt p3(-100.0,30.0,0.0);
    GC_MakeSegment ms2(p3, p2);
    Handle(Geom_TrimmedCurve) tc_line2 = ms2.Value();

    double distance_endpoint_linesegment_to_center_cirncunf2 = center.Distance(p2);
    printf("\nSETUP 2:\n");
    printf("========\n");
    printf("Description: Circle with touching NON-tangential line\n\n");
    printf("Distance from endpoint of line segment to center circunf: %f\n", distance_endpoint_linesegment_to_center_cirncunf2);
    printf("Distance from circunference to endpoint of line segment: %.10e\n\n", distance_endpoint_linesegment_to_center_cirncunf2 - radius);

    // Algorithm1: 2D intersection with Geom2dAPI_InterCurveCurve
    Handle(Geom2d_Curve) line2dCurve2;
    line2dCurve2 = GeomAPI::To2d(tc_line2, plane);


    printf("Algorithm: Geom2dAPI_InterCurveCurve - precision/tolerance: %.10g\n",precision);

    Intersector2d.Init(circle2dCurve, line2dCurve2, 1.0e-8);
    printf("\tGeom2dAPI_InterCurveCurve - NbPoints: %d\n", Intersector2d.NbPoints());
    printf("\tGeom2dAPI_InterCurveCurve - NbSegments: %d\n", Intersector2d.NbSegments());

    for (int i=1; i <= Intersector2d.NbPoints(); i++) {
        gp_Pnt2d p = Intersector2d.Point(i);
        printf("\t%d: (%f,%f,0)\n",i,p.X(),p.Y());
    }

    // Algorithm2: GeomAPI_ExtremaCurveCurve
    printf("\nAlgorithm: GeomAPI_ExtremaCurveCurve - precision/tolerance: %.10g\n",precision);

    GeomAPI_ExtremaCurveCurve Intersector3d2(circle, tc_line2);

    printf("\tGeomAPI_ExtremaCurveCurve - NbExtrema: %d\n", Intersector3d2.NbExtrema());

    return 0;
}

Additional information
and documentation updates
Output of the binary:

SETUP 1:
========
Description: Circle with touching tangential line

Distance from endpoint of line segment to center circunf: 48.019394
Distance from circunference to endpoint of line segment: 1.0373923942e-12

Algorithm: Geom2dAPI_InterCurveCurve - precision/tolerance: 1e-08
        Geom2dAPI_InterCurveCurve - NbPoints: 0
        Geom2dAPI_InterCurveCurve - NbSegments: 0

Algorithm: GeomAPI_ExtremaCurveCurve - precision/tolerance: 1e-08
        GeomAPI_ExtremaCurveCurve - NbExtrema: 0

SETUP 2:
========
Description: Circle with touching NON-tangential line

Distance from endpoint of line segment to center circunf: 48.019394
Distance from circunference to endpoint of line segment: 1.0373923942e-12

Algorithm: Geom2dAPI_InterCurveCurve - precision/tolerance: 1e-08
        Geom2dAPI_InterCurveCurve - NbPoints: 2
        Geom2dAPI_InterCurveCurve - NbSegments: 0
        1: (-31.501464,67.029738,0)
        2: (-49.768868,57.154532,0)

Algorithm: GeomAPI_ExtremaCurveCurve - precision/tolerance: 1e-08
        GeomAPI_ExtremaCurveCurve - NbExtrema: 4



TagsNo tags attached.
Test case number
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2018-10-08 16:58 abdullah New Issue
2018-10-08 16:58 abdullah Assigned To => msv
2018-10-08 18:19 msv Description Updated View Revisions
2018-10-08 18:19 msv Steps to Reproduce Updated View Revisions
2018-10-08 18:19 msv Additional Information Updated View Revisions
2018-10-08 18:20 msv Assigned To msv => ifv
2018-10-08 18:20 msv Status new => assigned
2018-10-08 18:21 msv Target Version => 7.4.0*


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker