4
$\begingroup$

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:

{{0.`,0.`,-1.`},{0.06120871905481365`,0.2397127693021015`,-0.9689124217106447`},{0.22984884706593015`,0.42073549240394825`,-0.8775825618903728`},{0.4646313991661485`,0.49874749330202717`,-0.7316888688738209`},{0.7080734182735712`,0.4546487134128408`,-0.5403023058681397`},{0.9005718077734668`,0.2992360720519783`,-0.3153223623952687`},{0.9949962483002227`,0.0705600040299336`,-0.0707372016677029`},{0.9682283436453982`,-0.17539161384480992`,0.17824605564949209`},{0.826821810431806`,-0.37840124765396416`,0.4161468365471424`},{0.6053978997153898`,-0.48876505883254856`,0.6281736227227391`},{0.35816890726838696`,-0.4794621373315693`,0.8011436155469337`},{0.14566511285437003`,-0.35277016278519596`,0.9243023786324636`},{0.01991485667481699`,-0.13970774909946293`,0.9899924966004454`},{0.011706187135988248`,0.10755999404390776`,0.9941296760805463`},{0.12304887282834767`,0.32849329935939453`,0.9364566872907963`},{0.32668234108248706`,0.4689999883873694`,0.8205593573395608`},{0.5727500169043067`,0.4946791233116909`,0.6536436208636119`},{0.8010059513424118`,0.39924355631174513`,0.4460874899137928`},{0.9555651309423384`,0.20605924262087827`,0.2107957994307797`},{0.9985860780981893`,-0.03757556023090465`,-0.03760215288797655`},{0.9195357645382262`,-0.2720105554446849`,-0.28366218546322625`},{0.7377684639979962`,-0.4398478799858351`,-0.5120854772418407`},{0.49778715100597465`,-0.49999510327535174`,-0.70866977429126`},{0.258347620623497`,-0.4377260873442142`,-0.8611924171615208`},{0.07807302063375395`,-0.26828645900021747`,-0.960170286650366`},{0.`,0.`,-1.`}}

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?

$\endgroup$
1
  • 1
    $\begingroup$ Interpolate with option PeriodicInterpolation->True. $\endgroup$ Jul 12, 2020 at 12:54

1 Answer 1

5
$\begingroup$

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] & /@ 
     Transpose[dat]},
  {ListPointPlot3D[dat, PlotStyle -> Orange], 
    ParametricPlot3D[#[t] & /@ ff // Evaluate, {t, 1, Length[dat]}]} //
    Show]
$\endgroup$
8
  • $\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, 2020 at 12:56
  • $\begingroup$ There is no interpolation. The curve is not smooth. $\endgroup$ Jul 12, 2020 at 12:57
  • $\begingroup$ What is the purpose of PeriodicInterpolation -> True when it works exactly same without it? $\endgroup$ Jul 12, 2020 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, 2020 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$ Jul 12, 2020 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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