Let's say, we have a list of points such as
Points = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
This is nothing but the corners of a square. List Plot:
Now I wanted to write a general function that connects the points I came up with this
PointList2Curve[pointlist_] :=
Module[{pointlist0 = pointlist, pathpatchs, Supports, Direcs, F},
Direcs =
Table[pointlist0[[i + 1]] - pointlist0[[i]], {i, 1,
Length[pointlist0] - 1}];
Supports = pointlist0[[;; -1]];
pathpatchs =
Table[Function[{t}, Supports[[i]] + t*Direcs[[i]]], {i, 1,
Length[pointlist0] - 1}];
F[t_] := Module[{t0 = t, i},
i = IntegerPart[t];
pathpatchs[[i + 1]][t - i]];
F
];
If I then have the function returned as in
X = PointList2Curve[Points];
and then do a parametric plot,
ParametricPlot[X[t], {t, 0, 4}]
This is of course not what it should look like. What should be happening is that that I get a square. I am pretty sure that, as far as I understand everything there is no logical mistake. After some trying I found that if I shorten the function such that the module returns only pathpatchs
, (The line segments of the paths) They turn out to be all the same. Now my question is, why is that and does anybody have an idea how to fix that ?
Thanks in advance !
I get
Table[Function[{t}, Supports[[i]] + t*Direcs[[i]]], {i, 1, Length[pointlist0] - 1}]
. Try that just on its own somewhere with an arbitrary value for the max of i. $\endgroup$