# How can I sort a data in specific form for Interpolation?

I have data of closed shape form

ListPlot[data, AspectRatio -> 1]


I would like to Interpolate this data to get the missing points so I am using BSplineFunction like this

interdata=BSplineFunction[Flatten[points, 1]];
ParametricPlot[bsF[t], {t, 0, 1}]


as you can see, the data needs to be sorted in a specific way to make all the points on the circumference of the closed shape and get something like this

Update

The last thing I would like to do is to get points on the circumference that are equally spaced. my idea was that after interpolation I will be able to do that. According to @kglr answer, it can be done as follows

equallyspaceddata = Table[{bsF[t]}, {t, 0, 1, 0.01}];
ListPlot[equallyspaceddata, AspectRatio -> 1, PlotStyle -> Black]


as you can see the points in the top half are denser compared to the bottom one. How can I get equally spaced points?

Update: " to get points on the circumference that are equally spaced":

Use MeshFunctions -> {ArcLength} and Mesh -> m to get m equally-spaced points on the parametric curve:

m = 50;

ParametricPlot[bsF[t], {t, 0, 1},
MeshFunctions -> {ArcLength},
Mesh -> m,
MeshStyle -> Directive[PointSize @ Medium, Red],
Epilog -> {Directive[PointSize @ Medium, Green], Point @ bsF[0]}]


fcp = FindCurvePath[data];

sorteddata = data[[fcp[[1]]]];

ListLinePlot[sorteddata, AspectRatio -> 1]


bsF = BSplineFunction[sorteddata];

ParametricPlot[bsF[t], {t, 0, 1}]


Try also ListCurvePathPlot:

ListCurvePathPlot[data]


• AWESOME, thanks a lot! Dec 28, 2021 at 9:25
• may you please see my update? Dec 28, 2021 at 10:29
• Thanks, but how can I get the red pint as a list to use them in a calculation? Dec 28, 2021 at 11:55
• @valarmorghulis, one way is to extract the point coordinates from ParametricPlot: e.g,, pp=ParametricPlot[..., MeshFunctions -> {ArcLength}, Mesh ->50]; pointcoords= Cases[Normal@pp, Point[x_] :> x, All]
– kglr
Dec 28, 2021 at 12:24
data = Import["/Users/roberthanlon/Downloads/data.dat"];


Since you are dealing with a circle:

EDIT 2: Using minimization to determine the center and radius

{center, radius} = {{x0, y0}, r} /. Minimize[{Total[
(EuclideanDistance[#, {x0, y0}] - r)^2 & /@ data],
r > 0}, {x0, y0, r}][[2]]

(* {{-4.22506*10^-14, -4.04645*10^-14}, 0.693182} *)

Manipulate[
Graphics[{
AbsoluteThickness[1], Red,

EDIT: Version 13 has a new function RegionFit
{center, radius} = List @@ RegionFit[data, "Circle"]