# compute the distance of a point to a curve maybe a bug?

I have used the Extrema_ExtPC to compute the distance from a point to a curve, and I have test all most of the curve type such as circle ellipse bezier and bspline, but I find out that sometimes this method can not compute a min distance with a given points, whats the problem? Can anybody help me figure out?

Here are the source code:

#define WNT
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main(int argc, char* argv[])
{
// Handle(Geom_Curve) circle = new Geom_Circle(gp::YOZ(), 1.0);
/* Handle(Geom_Ellipse) circle = new Geom_Ellipse(gp::YOZ(), 1.0, 0.3);*/

TColgp_Array1OfPnt poles(1, 4);
poles.SetValue(1, gp_Pnt(-1, -1, 0));
poles.SetValue(2, gp_Pnt(1, 2, 0));
poles.SetValue(3, gp_Pnt(3, 0, 0));
poles.SetValue(4, gp_Pnt(4, 1, 0));
// Handle(Geom_BezierCurve) circle = new Geom_BezierCurve(poles);

TColgp_Array1OfPnt ctrlPnts(1, 3);
TColStd_Array1OfReal knots(1, 5);
TColStd_Array1OfInteger mults(1, 5);

ctrlPnts.SetValue(1, gp_Pnt(0, 1, 0));
ctrlPnts.SetValue(2, gp_Pnt(1, -2, 0));
ctrlPnts.SetValue(3, gp_Pnt(2, 3, 0));

knots.SetValue(1, 0.0);
knots.SetValue(2, 0.25);
knots.SetValue(3, 0.5);
knots.SetValue(4, 0.75);
knots.SetValue(5, 1.0);

mults.Init(1);

Handle(Geom_BSplineCurve) circle = new Geom_BSplineCurve(ctrlPnts, knots, mults, 1);

// Handle(Geom_Curve) aCurve = BRep_Tool::Curve(edge, dFirst, dLast);

//get the parameters
Standard_Real f = pseudoCurve.FirstParameter();
Standard_Real l = pseudoCurve.LastParameter();
//f = 0.0 ; l = 4.0

//create 2 points to project on the wire
gp_Pnt P1(0,5,5);//for this one I'm expecting param = 0.5
gp_Pnt P2(0,0,5);//for this one, I'm expecting param = 3.5

gp_Pnt newP1,newP2;
Standard_Real newVal1,newVal2;
Extrema_ExtPC ext1(P1,pseudoCurve,f,l);
if ( ext1.IsDone() && ext1.NbExt() > 0 )
{
for ( Standard_Integer i = 1 ; i {
if ( ext1.IsMin(i) )
{
newP1 = ext1.Point(i).Value();
cout cout //break;
}
}
}
Extrema_ExtPC ext2(P2,pseudoCurve, f, l);
if ( ext2.IsDone() && ext2.NbExt() > 0 )
{
for ( Standard_Integer i = 1 ; i {
if ( ext2.IsMin(i) )
{
newP2 = ext2.Point(i).Value();
cout cout }
}
}

return 0;
}

Thanks very much!
Bing Yi

Dear yibing,

I would suggested you try to check it firstly in DRAW using
Draw command . You also can consult with
implementation of this command located at the file BRepTest_ExtremaCommands.cxx.
In case if the problem(s) will be reproduced in Draw too I would suggested you
to register the issue in Mantis Bugtracker which is available via the Collaborative portal - http://dev.opencascade.org/index.php?q=home/get_involved.

Best regards
FSR