I need to find out the closest point on the curve… The point that the ClosestPoint () method used in the curve class is not the closest point… I don’t know what’s going on.
Can you post an example of this? I think it’s hard to tell what is going on without the geometry and code.
-Willem
get closest point on curve:
const ON_Curve* tempCurve =…;
ON_3dPoint pt_closest;
double t=0.0;
if (tempCurve->GetClosestPoint(pt,&t))
{
pt_closest=tempCurve->PointAt(t);
}
Curve s_cur = s_obj.Curve(); //Here is the object converted to the curve
Curve g_cur = g_obj.Curve();//Here is the object converted to the curve
//The reconstructed curves are obtained from NurbsCurve
NurbsCurve n_cur1 = g_cur.ToNurbsCurve().Rebuild(s_cur.ToNurbsCurve().Points.Count,3,true);
NurbsCurve n_cur2 = g_cur.ToNurbsCurve().Rebuild(g_cur.ToNurbsCurve().Points.Count,3,true);
//The closest point on the curve obtained from the control point to curve 1 is on the curve 2.
List<Point3d> c_pt= new List<Point3d>();
for (int i = 0; i < g_n_cur.Points.Count; i++)
{
doc.Objects.AddPoint(g_n_cur.Points[i].Location);
double t;
n_cur2.ClosestPoint(n_cur1.Points[i].Location, out t);
Point3d pt = n_cur2.PointAt(t);
c_pt.Add(pt);
}
The above is a section of code, can get to the point to add to the Rhino is always wrong, all the points are on the Curve1
NurbsCurve cur2 = g_cur.ToNurbsCurve().Rebuild(s_cur.ToNurbsCurve().Points.Count,3,true);
NurbsCurve cur1 = g_cur.ToNurbsCurve().Rebuild(g_cur.ToNurbsCurve().Points.Count,3,true);
List<Point3d> c_pt = new List<Point3d>();
for (int i = 0; i < cur1.Points.Count; i++)
{
double t;
cur2.ClosestPoint(cur1.Points[i].Location, out t);
c_pt..Add(pt);
}
NurbsCurve cur1 = g_cur.ToNurbsCurve().Rebuild(s_cur.ToNurbsCurve().Points.Count,3,true);
NurbsCurve cur2 = g_cur.ToNurbsCurve().Rebuild(g_cur.ToNurbsCurve().Points.Count,3,true);
List c_pt = new List();
for (int i = 0; i < cur2.Points.Count; i++)
{
double t;
cur1.ClosestPoint(cur2.Points[i].Location, out t);
Point3d pt = s_n_cur.PointAt(t);
c_pt.Add(pt);
}
NurbsCurve cur1 = g_cur.ToNurbsCurve().Rebuild(s_cur.ToNurbsCurve().Points.Count,3,true);
NurbsCurve cur2 = g_cur.ToNurbsCurve().Rebuild(g_cur.ToNurbsCurve().Points.Count,3,true);
List<Point3d> c_pt = new List<Point3d>();
for (int i = 0; i < cur1.Points.Count; i++)
{
double t;
cur2.ClosestPoint(cur1.Points[i].Location, out t);
Point3d pt = s_n_cur.PointAt(t);
c_pt.Add(pt)
}
NurbsCurve cur1 = g_cur.ToNurbsCurve().Rebuild(s_cur.ToNurbsCurve().Points.Count,3,true);
NurbsCurve cur2 = g_cur.ToNurbsCurve().Rebuild(g_cur.ToNurbsCurve().Points.Count,3,true);
List<Point3d> c_pt = new List<Point3d>();
for (int i = 0; i < cur1.Points.Count; i++)
{
double t;
cur2.ClosestPoint(cur1.Points[i].Location, out t);
Point3d pt = cur2.PointAt(t);
c_pt.Add(pt)
}
Ok, and now a curve and a point in a 3dm file that reproduce the problem. The code looks good to me.