Page 1 of 1

[Sketcher] Constraints on b-spline knots with max multiplicity

Posted: Sat Feb 26, 2022 1:34 pm
by jnxd
When a knot in a b-spline is repeated "m" times where "m = degree of the spline", something interesting happens: the knot point is now coincident with a control point (a.k.a. pole). This can be useful if we want the b-spline to pass through a certain point, or to apply any other constraint we want by applying that on the control point(NOTE: remember we still lose the C1 continuity at the knot).

In Sketcher's implementation of b-splines, however, we encounter an issue. Only one of the coincident points can be selected and currently that is the knot, so only operations that can act on them (viz. multiplicity change) can be performed. Realthunder does have some fixes to select other points (and entities in general) when possible, but he will not be doing that for 0.20 [1]. So right now I am trying to make a workaround that will be usable with what we have right now.

The first option is to bring the control points to the "front" so they are what are selected instead of the knots. However, doing this will cause a problem when trying to change the knot's multiplicity, so we have just "inverted" the problem. So instead what I am trying to do is to implement a getConstrainableVertex() method so that if Sketcher notices the user is trying to constrain a knot, it tries to look for alternatives before cancelling the operation. This involves the following steps:
  1. Find the index of the knot in the b-spline and check it's multiplicity. Proceed only if it's high enough.
  2. Find the index of the control point that controls this knot point in the b-spline .
  3. Apply the constraint on the point.
So now, coming to the implementation issues I'm having:
  1. How to find the index of the knot without going through all the constraints? There is a relatively quick way to see a given sketcher vertex is a knot using GeometryFacade::getInternalType() but no way to find the internal position itself there.
  2. How to find the corresponding index of the pole? This is just math though so it can be done quickly.
  3. How to find the sketcher vertex for the pole? This is the reverse of 1. and can be done by a search but there might be a faster way.
  4. Do we really change from knots to poles all the time? Certain constraints can still be applied to knots if they are "non-driving". If the constraints are being created in "driving" mode, the user's intention is clear. However if the constraints are being created in "non-driving" mode, then the user may want to just get the coordinates of the knot or such. For the case of coordinates, even if there is a pole on the knot, one can decrease it's multiplicity and still want the new coordinates of the knot point.
[1] https://github.com/FreeCAD/FreeCAD/pull ... r810381456