Search code examples
curve-fittingsmoothingbspline

How to connect two fitted B-spline curve?


I use B-spline curve fitting to obtain one smooth curve. If I obtain two smooth B-spline , how can I connect then smoothly. For example, I have 59 points((x0,y0,z0),...,(x58, y58, z58)) and I have two fitted B spline. One B-spline is for the first 30 points, another is for the next 30 points and the two point set share one common point((x29,y29,z29)). The point (x29,y29,z29) will be modified twice due to curve fitting and will have two new positions. If I just connect the two new positions, the final curve will not be smooth at the point (x29,y29,z29). Currently I perform curve fitting for all data together but that will modify the smooth curve for the first 30 points entirely. I hope to only modify the connecting part of the first smooth curve. I know I need to impose derivatives need to be equal at the joint. I don't know how to do that.


Solution

  • It looks like you are doing LS fitting with B-spline curves or something similar and in general the B-spline obtained this way will not pass any of the data points. This is why the two B-splines do not meet at the common point.

    To solve this problem, you can enhance your LS fitting function to take constraints as part of the input. In your cases, these constraints are linear and therefore your problem will still be linear. Once this step is done, you can pre-calculate the slope at the common point and constrain both B-spline fitting to the common point and common slope. This way the two B-splines obtained will at least be G1 continuous at the common point.

    Having said this, to implement a constrained LS fitting is not a trivial task, which cannot be easily elaborated here either. So, you will have to do some "googling" yourself. An alternative solution will be to "tweak" your two B-splines to make them connected in a G1 manner. But doing so will certainly increase the fitting error as the sense of least squared error is destroyed. By "tweaking", I meant to change the B-spline's control points locally. In the following I will give more details.

    Supposed you have two B-splines C1(t) and C2(t) and the last two control points of C1(t) are P(n-2) and P(n-1) and the first two control points of C2(t) are Q(0) and Q(1). P(n-1) and Q(0) are supposed to be close to the common point (x29, y29, z29) of the two data set. Tweaking the B-spline curves simply means changing the location of P(n-2), P(n-1), Q(0) and Q(1) so that these two B-spline curves will meet in a G1 manner. To do this,

    1) we first make them G0 by moving both P(n-1) and Q(0) to the same location, which can be (x29, y29, z29) or simply the midpoint between P(n-1) and Q(0). Let's denote this new location as R.

    2) Now, check if P(n-2), R and Q(1) are collinear. If they happens to be collinear, then the two B-spline curves will be G1 as well and you are done. If they are not collinear, find the best approximating line passing thru R from P(n-2) and Q(1), then project P(n-2) and Q(1) onto this line and use the projected points as the new location of P(n-2) and Q(1).

    After these two steps, these two B-spline curves should be connected in G1 manner. But the error to the original data points around the common joint will become bigger.