Best spline method for closed curves

2.7k Views Asked by At

What is the best spline method I can use to obtain a closed curve for the following data?

Note that I will need to obtain the derivative as in every point there will be a vector that is perpendicular to the contour curve (the shape does not have to be a "circle like" as the example, but can be any closed shape).

enter image description here

3

There are 3 best solutions below

0
On BEST ANSWER

You can construct a closed b-spline curve, as described here.

I don't know if this is the "best" method -- only you can decide what you mean by "best".

If you know the curve normal at each point, then the problem is simpler, but I can't tell whether this is the case, based on the wording of your question.

3
On

This is meant to be complementary to bubba's answer and to the reference cited therein, which well explain the general approach in Cartesian coordinates.

To my experience and intuition, when we are dealing with closed curves, considering to work in polar coordinates might be of advantage.

that would mean to:
- move the reference system at the centroid of the cloud;
- convert the points and the normal vectors into polar c.;
- perform the spline method in $r,\theta$.

The advantage of working in polar c. is clear when you note that $r=const.$ is a circle, and the added terms will account for the deviation from that.

Also, since $r(\theta)$ is intrinsically periodic, it might be interesting to interpolate through Trigonometric Polynomials.

From the mathematical point of view, the choice of the reference system is quite arbitrary, and mainly dictated by computational advantage.

If instead the curve originates from a physical model, the choice will be oriented by physical considerations. For instance the physical motivation of the Spline method (as the word reminds) is to approximate the curve through a ductile wire, so in the $x,y$ plane. While, if it is the orbit of a particle in a central field ...

0
On

For an interpolating closed curve you can use a parametric spline with periodic boundary condition:

  1. Create a time-coordinate, e.g. proportional to the distance of two adjacent grid points: $t_{i+1}=t_i+\sqrt{(x_{i+1}-x_i)^2+(y_{i+1}-y_i)^2})$
  2. Create two splines for each $x$ and $y$ coordinate as a function of time. Set boundary conditions to be periodic, i.e. $f'(t_1)=f'(t_n)$.

In R you can do something like

# generate some input data
n=10
phi=sort(runif(n,0,2*pi))
r=rnorm(n,10,0.5)
X=r*cos(phi)
Y=r*sin(phi)
plot(X,Y)
# add first point to the end to create a closed loop
X=append(X,X[1])
Y=append(Y,Y[1])

# create time vector (traverse at constant speed)
T=vector(length=length(T))
T[1]=0
for(i in 2:length(Y)) T[i]=T[i-1]+norm(c(X[i]-X[i-1], Y[i]-Y[i-1]), type="2")

# setup periodic splines for both x and y coordinate
sx=splinefun(T,X,method="periodic")
sy=splinefun(T,Y,method="periodic")

# plot splines
Tplot=seq(T[1],tail(T,n=1),by=0.02)
Xplot=sx(Tplot)
Yplot=sy(Tplot)
lines(Xplot,Yplot)

The spline also contains information regarding derivatives: $\text{derivative} = (sx'(t), sy'(t))$.

# plot some derivatives and normals
Tplot=seq(T[1],tail(T,n=1),by=2.0)
for(t in Tplot)
{
    x = sx(t)
    y = sy(t)
    arrows(x,y,x+sx(t,deriv=1),y+sy(t,deriv=1),length=0.05) # derivative
    arrows(x,y,x+sy(t,deriv=1),y-sx(t,deriv=1),length=0.05) # normal
}

This gives

closed spline closed spline with derivative and normal arrows