0% found this document useful (0 votes)
44 views4 pages

Bspline Constraints

The document outlines new constraints related to B-splines introduced in FreeCAD's Sketcher between August and October 2022, detailing the mathematical foundations and implementation strategies. It discusses knot position constraints, rational B-splines, point on curve constraints, and tangent at knot constraints, providing equations and error definitions for each case. The implementation involves using the de Boor algorithm and specific constraint classes to manage the B-spline functionalities effectively.

Uploaded by

imfanshilin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Bspline Constraints

The document outlines new constraints related to B-splines introduced in FreeCAD's Sketcher between August and October 2022, detailing the mathematical foundations and implementation strategies. It discusses knot position constraints, rational B-splines, point on curve constraints, and tangent at knot constraints, providing equations and error definitions for each case. The implementation involves using the de Boor algorithm and specific constraint classes to manage the B-spline functionalities effectively.

Uploaded by

imfanshilin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

New Constraints Related to B-splines in

FreeCAD Sketcher
Ajinkya Dahale
October 2022

Following lists the logic behind and equations involved in the new constraints
introduced in Sketcher during the August–October 2022 B-splines constraint
project. For understanding where these fit into the planegcs solver architecture,
please refer to Abdullah Tahiri’s document on the same.

1 Preliminaries
We have the general parametric equation of a B-spline, i.e a spline S of degree
n in terms of basis splines Bi,n , 1 ≤ i ≤ k
X
Sn,t = αi Bi,n (u) (1)
i

where t = {t1 , t2 , t3 , ..., tk+n+1 } is the (non-decreasing) “flattened” knot vector


(i.e. m-multiplicity knot is repeated m times); {α1 , α2 , ..., αk } are the k “control
points” (in sketcher each will be a 2D vector for a non-rational spline).
We do not delve into the exact expressions and definitions for Bi,n , but
these are already well documented. Often we do not directly calculate Bi,n (u),
but directly compute Sn,t using algorithms like Cox-de Boor. However, for our
purposes, we will need these values themselves, and these can be obtained from
the same algorithms using the formula
X
Bj,n = δij Bi,n (u) (2)
i

where δij is the Kronecker delta function.

2 Knot position constraints


Now, let us look at how a knot of a (non-rational) B-spline can be handled. Let
a vertex identified by it’s position q be constrained to be at a parameter u = U .
For any given knot, we can constrain u = ti instead, and the equation does not
change.
Then, we want
X
q= pi Bi,n (U ) (3)
i

1
where pi are the positions of the control points. The point vector to be passed
to the solver is {qx , qy , p1x , p1y , ..., pkx , pky }.
We then define the errors as
X
ex = q x − pix Bi,n (U ) (4)
i
X
ey = q y − piy Bi,n (U ) (5)
i

We can also get the gradients as

∂ex /∂qx = 1 (6)


∂ex /∂pix = −Bi,n (U ) (7)

and similar for ey .


Thus, every internal knot constraint in Sketcher is represented by two con-
straints in the solver.

2.1 Case for rational B-splines


In the current implementation in Sketcher, all B-splines are rational, with their
control point weights by default set to unity. But if we need to truly support
any B-spline, we must consider cases where they are different.
The equation then becomes
X X
q= wi pi Bi,n (U )/ wi Bi,n (U ) (8)
i i

where wi are the weights of the control points. The point vector then becomes
{qx , qy , p1x , p1y , ..., pkx , pky , w1 , w2 , ..., wk }.
We then define the errors as follows, to avoid the complications arising by
the division
X X
ex = wi Bi,n (U )qx − wi pix Bi,n (U ) (9)
i i
X X
ey = wi Bi,n (U )qy − wi piy Bi,n (U ) (10)
i i

Then the gradients are


X
∂ex /∂qx = wi Bi,n (U ) (11)
i
∂ex /∂pix = −wi Bi,n (U ) (12)
∂ex /∂wi = (qx − pix )Bi,n (U ) (13)

and similar for ey .

2.2 Implementation
Each constraint is then implemented as a ConstraintWeightedLinearCombination,
with the Bi,n (U ) values stored directly as linear combination factors.

2
Since B-splines have a local support, we only need to consider upto n + 1
control points. Further, for a knot with multiplicity m, we only need to consider
n + 1 − m control points (with minimum of 1 for the end-points that have
multiplicity n + 1).
Since a flattened set of knots is needed for running the de Boor algorithm,
they are derived from the un-flattened knot vector and the multiplicity vector
within the BSpline object and stored separately.

3 Point on Curve Constraint


For constraining point on a B-spline, we can exploit the same equation (8), but
also allow U to be variable. The point vector then becomes {qx , qy , U, p1x , p1y , ..., pkx , pky , w1 , w2 , ..., wk }.
The error equations can be kept the same as (9), however, the gradients
become
X
∂ex /∂qx = wi Bi,n (U ) (14)
i
∂ex /∂pix = −wi Bi,n (U ) (15)
∂ex /∂wi = (qx − pix )Bi,n (U ) (16)
X X
∂ex /∂U = wi (∂Bi,n (U )/∂U )qx − wi pix (∂Bi,n (U )/∂U ) (17)
i i

3.1 Implementation
This constraint is implemented as ConstraintPointOnBSpline. We cannot now
store Bi,n (U ), since it keeps changing. So we instead compute the sums directly
using de Boor algorithm.
We also use known derivative of B-spline (can be found in a textbook)

∂ X X αi − αi−1
αi Bi,n (u) = n Bi,(n−1) (u), (18)
∂u i i
ti+n − ti

over an appropriate range of indices.


One thing to note here is that we must use (n+1) control points, unlike knot
position constraints where we could use less. In principle, these control points
change as we move from one piece of the B-spline to another, but in the current
implementation, the point instead stays constrained to an extrapolation of the
original piece. In the next Sketcher solve, this point is expected to be snapped
to the closest point, which could be on a different piece.

3
4 Tangent at Knot
Once again, we look at controlling the slope of the B-spline at a fixed parameter
u = U.

The direction of the slope can be given by the vector ∂u Sn,t . For conve-
nience, we instead work with a parallel vector
!2
X ∂
r(u) = wi Bi,n (u) Sn,t (u)
i
∂u
! !
X X

= wi Bi,n (u) pi wi Bi,n (u)
i i
! !
X X

− wi Bi,n (u) pi wi Bi,n (u) (19)
i i

′ ∂
where Bi,n (u) = ∂u Bi,n (u).
We want this to be parallel to some vector, say l. An appropriate error
function then is
e = ẑ · (r(U ) × l) = rx (U )lx − ry lx (20)
Note that in addition to this, the l-vector comes from a line segment, and
we also want to constrain the knot to be on that line segment.
The gradients can be derived from
 
X

∂rx (u)/∂pix =  wj Bj,n (u) wi Bi,n (u)
j
 
X

− wj Bj,n (u) wi Bi,n (u), (21)
j
 
X

∂rx (u)/∂wi = Bi,n (u)  wj (pjx − pix )Bj,n (u)
j
 
X

−Bi,n (u)  wj (pjx − pix )Bj,n (u) , (22)
j

and similar expressions for y direction.

4.1 Implementation
This constraint is implemented as ConstraintSlopeAtBSplineKnot.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy