In Mathematica we have ListSurfacePlot3D for reconstructing surface from list of points in 3D. But I can not find something similar if I want to reconstruct a curve instead of a surface. For example if I have this list of points:


Notice that the curve should be a closed loop as the first and last points are the same. I want to find a smooth curve that passes exactly through these points. Something like this:

enter image description here

Any suggestion how to do it?

  • 1
    $\begingroup$ Interpolate with option PeriodicInterpolation->True. $\endgroup$ – Henrik Schumacher Jul 12 at 12:54

Following Henrik's suggestion, how about

 ff = Interpolation[#, PeriodicInterpolation -> True] & /@ Transpose[dat];
{ListPointPlot3D[dat, PlotStyle -> Orange],
ParametricPlot3D[#[t] & /@ ff//Evaluate, {t, 1, Length[dat]}]}//
  Show[#,BoxRatios -> {1, 1, 1}, Axes -> None] &

enter image description here

Note that following the OP's request, you can encapsulate this into a function:

ListCurvePlot3D[dat_] := 
 Module[{t, ff = 
    Interpolation[#, PeriodicInterpolation -> True] & /@ 
  {ListPointPlot3D[dat, PlotStyle -> Orange], 
    ParametricPlot3D[#[t] & /@ ff // Evaluate, {t, 1, Length[dat]}]} //
| improve this answer | |
  • $\begingroup$ OP mentions I want to find a smooth curve, but this has corners. Perhaps a BSplineFunction would be more appropriate? $\endgroup$ – flinty Jul 12 at 12:56
  • $\begingroup$ There is no interpolation. The curve is not smooth. $\endgroup$ – azerbajdzan Jul 12 at 12:57
  • $\begingroup$ What is the purpose of PeriodicInterpolation -> True when it works exactly same without it? $\endgroup$ – azerbajdzan Jul 12 at 13:15
  • $\begingroup$ @azerbajdzan i/ I tend to listen to what Henrik says because he is very smart. ii/ I guess you requested the path to be periodic: the documentation states that if this option is used you can evaluate t at values higher than Length[dat] and remain on the curve. I assume that it means internally it is using periodic functions to do the interpolation. For instance {t, -5, Length[dat] + 5} $\endgroup$ – chris Jul 12 at 13:21
  • $\begingroup$ I see... Now I wonder why they did not make one command like they did for surface. If we have ListSurfacePlot3D we could also have ListCurvePlot3D. Thanks. $\endgroup$ – azerbajdzan Jul 12 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.