I am not sure I am understanding this algorithm properly.
We use this algorithm, for example for intersections between two curves:
Code: Select all
bool GeomCurve::intersect( GeomCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
double tol) const
{
Handle(Geom_Curve) curve1 = Handle(Geom_Curve)::DownCast(handle());
Handle(Geom_Curve) curve2 = Handle(Geom_Curve)::DownCast(c->handle());
try {
if(!curve1.IsNull() && !curve2.IsNull()) {
GeomAPI_ExtremaCurveCurve intersector(curve1, curve2);
if (intersector.NbExtrema() == 0 || intersector.LowerDistance() > tol) {
// No intersection
return false;
}
for (int i = 1; i <= intersector.NbExtrema(); i++) {
if (intersector.Distance(i) > tol)
continue;
gp_Pnt p1, p2;
intersector.Points(i, p1, p2);
points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z()));
}
return points.size()>0?true:false;
}
else
return false;
}
catch (Standard_Failure& e) {
throw Base::RuntimeError(e.GetMessageString());
}
}
https://tracker.dev.opencascade.org/view.php?id=30217
I have found other cases where I get no result, and I am starting to think that maybe it is me, that I do not know how to use it, and not the algorithm.
The new case is this: There is a coincidence between the arc of circle and the line segment.
I have a stand alone c++ example where the intersection is not detected:
Code: Select all
# 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 <GC_MakeArcOfCircle.hxx>
# include <gp.hxx>
# include <gp_Ax2.hxx>
# include <gp_Pnt.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx>
# include <gp_Circ.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(-15.625722, -10.526889000000001, 0.0), p2(-16.296861005504617, -7.746175, 0.0);
GC_MakeSegment ms(p1, p2);
Handle(Geom_TrimmedCurve) tc_line = ms.Value();
// A circunference arc
gp_Pnt center(-16.614095762607519, -9.1963880000000007, 0.0);
double radius = 1.4845051823698976;
double StartAngle = 1.3554381905682238;
double EndAngle = 2.446854102374213;
gp_Dir norm(0,0,1);
gp_Ax2 xdir(center, norm);
GC_MakeCircle mc(xdir, radius);
Handle(Geom_Circle) circle = mc.Value();
GC_MakeArcOfCircle ma(mc.Value()->Circ(), StartAngle, EndAngle, 1);
if (!ma.IsDone()) {
printf("Unable to create arc!!");
return -1;
}
Handle(Geom_TrimmedCurve) arc = ma.Value();
// NOTE: Non-tangent line with coincident endpoint
double distance_endpoint_linesegment_startpoint_arc = arc->StartPoint().Distance(tc_line->EndPoint());
printf("SETUP:\n");
printf("========\n");
printf("Description: Arc of Circle with coincident line endpoint\n\n");
printf("Distance from endpoint of line segment to startpoint of arc: %e\n", distance_endpoint_linesegment_startpoint_arc);
GeomAPI_ExtremaCurveCurve Intersector3d(arc, tc_line);
printf("\tGeomAPI_ExtremaCurveCurve - NbExtrema: %d\n", Intersector3d.NbExtrema());
return 0;
}
Code: Select all
SETUP:
========
Description: Arc of Circle with coincident line endpoint
Distance from endpoint of line segment to startpoint of arc: 1.953993e-14
GeomAPI_ExtremaCurveCurve - NbExtrema: 0
Anybody familiar with this algorithm can help me out here? Is it a bug or is it me?Describes functions for computing all the extrema between two 3D curves. An ExtremaCurveCurve algorithm minimizes or maximizes the distance between a point on the first curve and a point on the second curve. Thus, it computes start and end points of perpendiculars common to the two curves (an intersection point is not an extremum unless the two curves are tangential at this point). Solutions consist of pairs of points, and an extremum is considered to be a segment joining the two points of a solution.