# Control points from a B-Spline

Is there any way I can retrieve the control points/polygon from a B-Spline (calculated from `Dierckx.jl` or `Interpolations.jl`)?

Control points as described here and shown as the black polygon here: For instance, in the following MWE, how would I get the control polygon of the following spline:

``````using Dierckx, Makie

x = range(0, stop=1, length=5)
y = [0.82, 0.23, 0.82, 0.46, 0.22]
sc = scatter(x, y)
spl = Spline1D(x, y)
xl = range(0, stop=1, length=100)
yl = spl.(xl)
lines!(sc, xl, yl)
``````

Thanks!

Just to make sure that I understood you correctly:
you want to have a function
`f(xl,yl) -> (x,y) `
I would guess that this is not unambiguously feasible unless you specify at least the `x` values for which you want the `y`. This is because multiple sets of `(x,y)` can lead to the same spline function. Using only the values of the spline function at different points `xl` does not make it any easier.

I assumed that given a set of discrete `xy` points and their corresponding spline (the result from, say, `Spline1D(x, y)`), I could get a unique control polygon. Ultimately I’d like to get a measure of how much the spline needed to “turn” to fit said points. I had hoped to get such a measure from the angles between the straight lines composing the polygon…

OK probably I’m turned completely wrong somewhere. But IMHO the (x,y) points are your control polygon already, why you don’t just connect them?

I think the (x,y) coordinates are the knots of the spline, which is different from the control points. I suspect that the control points are a artificial construct, and that these help visualize how the spline is generated, but do not have anything to do with the spline’s properties…

I am not sure what you are looking for here. B-splines are defined by a set of knots, are evaluated at some values x, and fit using a linear solution or least squares, to values or various derivatives. The x may or may not coincide with the knots — they don’t even have the same length, depending on how you set up the problem and the order of the splines

Here are some definitions:

1. xy coordinates: the data the spline is fitted to
2. spline knots: xy coordinates the fitted spline passes through
3. spline degree: the degree of the function describing the spline
4. control points/polygon: a bunch of straight lines that have some relation to the resulting spline.

I’m wondering if there is any way I can get the control points/polygon.
I just found this blog: https://opensourc.es/blog/bezier-curve about these control points. In any case, there is a nice illustration of these there, here it is:

1 Like

I think you are confusing B-splines with Bezier curves, they are different things.

Also, generally for B-splines, no “polygon” drawn, say, tangentially at various points would determine the spline except for some very special cases.

I think you are correct. OK, so I’ll drop the idea of these control points/polygon when it comes to B-splines.

I still need to read that book you mentioned, but check this continuation post @Wikunia wrote:
https://opensourc.es/blog/b-spline
It would be good to hear what Olle has to say too.

1 Like

Thanks for reaching out. I think you have a misunderstanding of knots here as it really is just a list of number and not of coordinates.
As mentioned I think the control polygon is not well defined. I normally construct it the other way around. It’s interesting though. Maybe one can dive deeper into the Julia package to find it out.
I think I’m not quite sure what you’re interested in exactly. Maybe just curvature? Or what do you mean by “turn”?

My understanding of that blog post is that it describes how to approximate a polygon with B-splines. Reconstruction of such a polygon is an interesting problem, but I am not sure it has a unique solution.

Thanks to you both!

What I’m truly after is some reliable measure of how curvy a section of a trajectory is.

I have a trajectory, a set of xy coordinates + time. These are noisy and not entirely reliable. I want to smooth the trajectory using splines. These trajectories are easily divided into two parts:

1. a more or less straight part where there are hardly any turns larger than 45 degrees.
2. a more curvy part where there is a mix of turns, some of which are 189 degrees.

I naively thought that it would be useful to describe the curviness of the trajectory as a function of the angle between each subsequent segments of the control polygon. This is why I’ve been asking about these control points/polygon…

At the end of the day I’m trying to do three things in one shot: smooth the data, allow for interpolation, detect where the straight part ends and the curvy part begins.

You could calculate the second derivative of the spline approximation at various points in that section. It is easy with B-splines (but make sure you use at least cubic).

I test this as well. Thanks!