Creat curve on on_mesh

I need write a function to creat curve on a on_mesh with some points on the mesh.
the function will like this:
on_curve* CreatCurveOnMesh(on_simpleArray<on_3dpoint>&in_ps,on_mesh* in_mesh);

I wirte this function as follow steps:
1: add many middle point based the in_ps array on the mesh,ensure the distance of the adjoin points are closest enough.
2:creat a curve using RhinoInterpCurve ,named curve A
3:rebulid the curve Using RhinoRebuildCurve().,named curve B

my problem is:
because the mesh is not very smoth,so the curve A is also not smoth,but is closet to the mesh enough.So I using RhinoRebuildCurve to want make the curve become more somth,but if I do that,The curve B will not coset to the mesh enough.
anyone Can give me some ideas how can I Creat the curve very smoth and coset to the mesh enough
2368c.rar (367.9 KB) is the test mesh

I am sorry,
the function will like this:
on_curve* CreatCurveOnMesh(on_simpleArray<on_3dpoint>&in_ps,on_mesh* in_mesh);

It looks like can’t edit angle brackets

You might try RhinoPullCurveToMesh(). See rhinoSdkMeshUtilities.h for details.

Rather than using curve interpolation, I would use curve approximation (fitting). Then the curve is more smooth through noisy data.

I am not sure if this is available in the Rhino C++ SDK, but you could write your own fit routine. For example, see http://www.dmg.tuwien.ac.at/geom/ig/papers/tr143.pdf