View Issue Details

IDProjectCategoryView StatusLast Update
0030217CommunityOCCT:Modeling Algorithmspublic2023-08-01 15:08
Reporterabdullah Assigned Toazv 
PrioritynormalSeveritymajor 
Status assignedResolutionopen 
PlatformUbuntu 18.04.1 LTS 64-bit 
Product Version7.3.0 
Target VersionUnscheduled 
Summary0030217: Modeling Algorithms - 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

Activities

git

2019-02-27 14:00

administrator   ~0082414

Branch CR30217 has been created by maxsson.

SHA-1: f1092ae92d38d13c0590ff9b558935c016f1d294


Detailed log of new commits:

Author: maxsson
Date: Wed Feb 27 13:39:26 2019 +0300

    0030217: Intersection between a circle and a line not detected WHEN TANGENT
    
    * 2D intersector takes into account the given tolerance when intersects line with circle.
    * Extrema curve-curve executes parametric branch in case of analytical has given zero solutions.
    * Command 'intersect' has been improved to show additional information about the area of tangency (start and end parameters on each curve).

maxsson

2019-02-27 14:16

developer   ~0082415

Please review.

git

2019-02-27 16:10

administrator   ~0082420

Branch CR30217 has been updated by maxsson.

SHA-1: 802cc1eddb6128dd5a0125dc2f4ef67c3ee261b8


Detailed log of new commits:

Author: maxsson
Date: Wed Feb 27 16:05:12 2019 +0300

    0030217: Intersection between a circle and a line not detected WHEN TANGENT
    
        * FIX Command 'intersect' has been improved to show additional information about the area of tangency (start and end parameters on each curve).

git

2019-02-27 16:33

administrator   ~0082421

Branch CR30217 has been updated forcibly by maxsson.

SHA-1: 3a636f3ee6f0491bc864a8348806fed43acaae0e

git

2019-03-01 17:29

administrator   ~0082528

Branch CR30217 has been updated by maxsson.

SHA-1: 977017f26d02c09b8d98ec2ed1f53d80a5bdb26c


Detailed log of new commits:

Author: maxsson
Date: Fri Mar 1 17:13:53 2019 +0300

    Preserving the value of parallelism before parametric branch

git

2019-03-06 14:00

administrator   ~0082729

Branch CR30217 has been updated forcibly by azv.

SHA-1: 5949fa544d26709d24583958ad44b8ecfe2a00fa

git

2022-07-29 10:03

administrator   ~0110069

Branch CR30217_1 has been created by azv.

SHA-1: 7fa7bd3f022d897cbce8fba228d5aed466810605


Detailed log of new commits:

Author: maxsson
Date: Wed Feb 27 13:39:26 2019 +0300

    0030217: Intersection between a circle and a line not detected WHEN TANGENT
    
    * 2D intersector takes into account the given tolerance when intersects line with circle.
    * Extrema curve-curve executes parametric branch in case of analytical has given zero solutions.
    * Command 'intersect' has been improved to show additional information about the area of tangency (start and end parameters on each curve).

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
2018-10-08 18:19 msv Steps to Reproduce Updated
2018-10-08 18:19 msv Additional Information Updated
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
2019-02-27 14:00 git Note Added: 0082414
2019-02-27 14:13 azv Assigned To ifv => maxsson
2019-02-27 14:16 maxsson Note Added: 0082415
2019-02-27 14:16 maxsson Assigned To maxsson => azv
2019-02-27 14:16 maxsson Status assigned => resolved
2019-02-27 15:58 kgv Summary Intersection between a circle and a line not detected WHEN TANGENT => Modeling Algorithms - Intersection between a circle and a line not detected WHEN TANGENT
2019-02-27 16:10 git Note Added: 0082420
2019-02-27 16:33 git Note Added: 0082421
2019-03-01 17:29 git Note Added: 0082528
2019-03-06 14:00 git Note Added: 0082729
2019-07-11 08:27 azv Status resolved => assigned
2019-07-11 08:27 azv Target Version 7.4.0 => 7.5.0
2020-09-14 23:04 msv Target Version 7.5.0 => 7.6.0
2021-08-29 18:53 msv Target Version 7.6.0 => 7.7.0
2022-07-29 10:03 git Note Added: 0110069
2022-10-24 10:40 szy Target Version 7.7.0 => 7.8.0
2023-08-01 15:08 dpasukhi Target Version 7.8.0 => Unscheduled