[Solved] BSPlineCurve insert Knots question.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: BSPlineCurve insert Knots question.

Post by edwilliams16 »

Chris_G wrote: Thu Aug 18, 2022 4:15 pm
I think a segmented curve perfectly matches its parent curve.
I believe that is certainly the case: https://pages.mtu.edu/~shene/COURSES/cs ... 0by%20one.

In fact it seems knot insertion on the boundaries is an essential part of the algorithm for creating a ruled BSplineSurface.

Look at BSplineCurves first. A curve in FreeCAD consists of a parameter range (conventionally in u ) and a function that maps each point in u to a corresponding point in 3D space, with

Code: Select all

curv.value(u)
.
BSpline curves, as very nicely put by @Chris_G , have a two-part structure, an algebraic part and a geometrical part. The geometrical part is a list of 3D points, P_i called poles or control points. The parameter range of u is divided into intervals

Code: Select all

u_0 <= u_1 <= u_2 ... u_m
. This list of interval is called the knot vector or knot sequence. Values can be repeated (note the possible equality) and the number of repeats is called the multiplicity of that particular value. In FreeCAD

Code: Select all

curv.KnotSequence
gives you the knot vector. The algebraic part of the scheme is an interpolation rule to be applied to the control points.
Bear with me. Let's start with the simplest possible rule - piecewise constant. For u_i < u < u_[i+1] we map u to P_i. This is not very useful as our curve is discontinuous, just a series of points one at each of the control points. The next possibility is for each interval in u to correspond to a straight line between its corresponding control point and the next one in the list. We map to a linear combination of P_i and P_[i+1]. Our curve is now a polygon connecting up the control points. (We also had to add an extra pole on the end of our list to give the last line segment somewhere to go to.)
We can imagine extending this scheme, taking linear combinations of more and more successive points. We progress from points to lines to quadratic curves to cubics. This is the degree of the BSpline - 3 for cubics etc. The curves get smoother and smoother as we do this.

Move on to BSpline surfaces. A surface maps points (u, v) into 3D space. The knots form a rectangular grid in (u, v) space defined by

Code: Select all

surf.UKnotSequence
surf.VKnotSequence
It took a while to get here, but the important point is there is only one knot vector in each direction of the surface. But when we make a ruled surface the two end curves in general will have different sequences. This is where knot insertion comes to the rescue. We create a merged sequence containing all the knots of both sequences (*). We then insert the extra knots in the two end curves (retaining their shape) so the two end curves now have the same knot sequence. This becomes the UKnotSequence of the ruled surface. The VKnotSequence is constructed to correspond the linear interpolation between the endpoints in the v direction.
Voila - ruled surface. Note by construction the straight lines of the ruling are lines of constant u. That is the way BSplines work. We don't have any alternative way of connecting up two curve segments.

One last piece of terminology that is potentially confusing. Interpolation is used in an unfamiliar way. The BSpline interpolation scheme, interpolates (takes weighted combinations of) the control points (poles), but only in special cases does the curve actually go through them. A more common usage of the term would be that the curves go through the points, but that is not the case here. Curves can be forced to go through given points by increasing their multiplicity, but only at the cost of smoothness.

EDIT (*) - After putting the two curves on the same parameter range. See https://forum.freecadweb.org/viewtopic. ... 57#p618757
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: BSPlineCurve insert Knots question.

Post by onekk »

edwilliams16 wrote: Thu Aug 18, 2022 6:34 pm ...

Many thanks, I have to digest the whole explanation :D

But I've guessed "main image" of the matter.

I'm copying down you explanation in my "personal notes" to keep them "for future needs".

Many thanks again @edwilliams16 and @Chris_G for your help.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply