B-Splines/pl

Ta strona opisuje jak używać krzywych złożonych w programie FreeCAD. Podaje również podstawowe informacje czym są krzywe złożone i do jakich zastosowań są przydatne.

Motywacja
Jeśli posiadasz już wiedzę na temat krzywych złożonych typu B-splines i ich zastosowania, możesz przejść bezpośrednio do rozdziału Krzywe złożone w programie FreeCAD.

Załóżmy, że chcesz zaprojektować część, która powinna być wytworzona za pomocą drukarki 3D. Część musi mieć krawędź zaprojektowaną w ten sposób:



Musisz wydrukować część w kierunku od dołu szkicu do góry. Zewnętrzne konstrukcje wsporcze mogą nie być rozwiązaniem. Dlatego musisz dodać podporę bezpośrednio do swojej części. Jakie masz opcje?


 * Opcja 1: możesz dodać linię od punktu (20, 0) do punktu (80, 40):



Jednak takie rozwiązanie wymaga dużej objętości, a co za tym idzie wagi i ilości materiału.


 * Opcja 2: możesz połączyć te dwa punkty łukiem okręgu. Aby zaoszczędzić na objętości, łuk powinien kończyć się stycznie w punkcie (80,40). Wtedy twoje rozwiązanie będzie wyglądać następująco:



W PORZĄDKU. Ale na dole nie potrzebujesz bezpośredniego wsparcia.


 * Opcja 3: możesz zaoszczędzić trochę więcej objętości, jeśli połączenie między dwoma punktami jest krzywą, która zaczyna się stycznie w punkcie o współrzędnych (0, 20) i kończy stycznie w (80, 40):



Tak więc krzywa, za pomocą której można połączyć dwa punkty stycznie do punktu odniesienia, może być bardzo przydatna w konstrukcjach. Krzywe Béziera zapewniają tę cechę.

Pochodne
Krzywe Béziera są wielomianami opisującymi połączenie między dwoma punktami. Najprostszym wielomianem łączącym dwa punkty jest prosta ($$A*x^1+B$$), zatem również liniowe krzywe Béziera są liniowe:



Jednak wielomian staje się użyteczny, gdy możemy go kontrolować. Powinien więc istnieć punkt pomiędzy dwoma punktami końcowymi, który pozwala nam określić jak punkty końcowe są połączone. Tak jak w powyższym przykładzie w opcji trzeciej krzywa jest przydatna, gdy zaczyna się i kończy stycznie do linii przecinających punkty końcowe. I to jest główna cecha krzywych Béziera. Dodajmy więc punkt kontrolny pomiędzy punktami końcowymi. Krzywa zacznie się stycznie do tego punktu kontrolnego, co oznacza, że jest styczna do linii, którą możemy narysować pomiędzy punktem początkowym a punktem kontrolnym. Idąc wstecz od punktu końcowego krzywa będzie również styczna do linii, którą możemy narysować pomiędzy punktem kontrolnym a punktem końcowym. Animacja numer 2 pokazuje jak wygląda taka krzywa.



Animacja jasno pokazuje, czym w zasadzie jest krzywa - przejściem od punktu P0 do punktu P2 poprzez obrócenie linii P0-P1 tak, aby stała się linią P1-P2. W ten sposób otrzymujemy ładną cechę stycznego początku / końca.

Taka krzywa może być opisana tylko wielomianem kwadratowym. (Liczba lewych / prawych obrotów + 1 to konieczny rząd wielomianu. Wielomian kwadratowy to jeden zwrot, wielomian sześcienny ma dwa zwroty, itd.) Dlatego krzywa Béziera z jednym punktem kontrolnym jest kwadratową (drugiego rzędu) krzywą Béziera.

Posiadanie tylko jednego punktu kontrolnego często nie jest wystarczające. Weźmy powyższy motywujący przykład. Tam w opcji 3 kończymy krzywą stycznie w kierunku x. Ale jak można połączyć punkty (20, 0) i (80, 40) tak, aby krzywa kończyła się stycznie w kierunku y? Aby to osiągnąć potrzebny jest najpierw zwrot w prawo, a potem w lewo, a więc wielomian sześcienny (trzeciego rzędu). A to oznacza, że dla krzywej Béziera potrzebujemy (lub można powiedzieć, że zyskujemy) drugi punkt kontrolny. Animacja 3 pokazuje sześcienną krzywą Béziera.



Aby odpowiedzieć na pytanie, rozwiązaniem z zakończeniem stycznym w kierunku y dla przykładu jest:



Matematyka
Jeśli jesteś zainteresowany, aby zrozumieć matematykę w tle, oto podstawy.

Krzywą Béziera oblicza się według poniższego wzoru:

$$\quad \textrm{Bezier}(n,t)=\sum_{i=0}^{n}\underbrace{\binom{n}{i}}_{\text{polynomial term}}\underbrace{\left(1-t\right)^{n-i}t^{i}}_{\text{polynomial term}}\; \underbrace{P_{i}}_{\text{point coordinate}} $$

"n" jest niniejszym stopniem krzywej. Zatem krzywa Béziera stopnia n jest wielokątem rzędu n. Współczynniki $$P_{i}$$ są więc współrzędnymi punktów kontrolnych krzywych Béziera. Wizualizację można znaleźć na stronie kontrolowanie krzywizn Béziera.

If you are further interested, have a look at this website with a nicely animated derivation of the math of Bézier curves.

Rules
In the above text you might already noticed some "rules" for Bézier curves:
 * The polynomial degree is also the degree of the curves.
 * If you need $$n$$ turns, you need at least a $$n+1$$ degree Bézier curve.
 * A Bézier curve always begins tangentially to the line between the startpoint and the first control point (and ends tangentially to the line between the last control point and the endpoint).

Basics
This video lists at the beginning the practical problems with Bézier curves. For example that adding or changing a control point changes the whole curve. These problems can be resolved by joining several Bézier curves. The result is a so-called spline, in particular a B-spline (basis spline). The video also explains that a union of quadratic Bézier curves forms a uniform quadratic B-spline and that a union of cubic Bézier curves forms a uniform cubic B-spline.

From the videos we can collect useful "rules" for B-splines:
 * The first and last control point is the end/start point of the spline.
 * Like for Bézier curves, splines always begin tangentially to the line between the startpoint and the first control point (and end tangentially to the line between the last control point and the endpoint).
 * A union of $$S$$ Bézier curves with the degree $$D$$ has $$S+D$$ control points.
 * Since one is in most cases working with cubic B-splines we can then state that $$N$$ control points lead to $$N-3$$ Bézier segments and in turn $$N-4$$ segment junction points.
 * A B-spline with the degree $$D$$ offers at every point a continuous $$D-1$$ order derivative.
 * For a cubic B-spline this means that the curvature (second order derivative) does not change when traveling from one segment to the next one. This is a very useful feature as we will later see.

If you are interested in more details about B-Spline properties, have a look at this video.

Basis
The name B-spline stands for Basis spline. Instead of forming the spline as a combination of Bézier curves, the approach is to to model the same spline a different way. The idea is hereby to use another set of polynomials as basis. A linear combination of these basis polynomials $$B_D(t)$$ with the order $$D$$ forms the B-spline. This video explains the transition from the Bézier control points to the polynomial basis functions describing the spline. Mathematically we can describe a B-spline with this formula:

$$\quad c(t)=\sum_{k=0}^{N}p_{k}B_{k, D}(t) $$

Hereby $$p_k$$ is the $$k$$-th control point of the B-spline and also a factor for the $$k$$-th base polynomial $$B_{k, D}(t)$$. Every basis polynomial describe the spline in a certain region and therefore moving a control point does not affect the whole spline. To understand this, it is highly recommended to have a look at this video starting at minute 2:23.

As explained in the video, the basis polynomials are Bernstein polynomials. The set of basis polynomials for a certain B-spline can be visualized this way:



At every spline position $$t$$ the sum of polynomials is 1 (indicated by the orange line). At the start only the red polynomial has an influence since all other polynomials are there 0. At greater $$t$$ the spline is described by a linear combination of different basis polynomials. In the image above, every polynomial is greater than 1 for the whole range $$0 < t < 1$$. This is not necessarily the case. As shown in the video, the basis polynomials are basically only greater than 0 for a certain spline position range. The interval at which a basis polynomial is greater than 0 is described by the knot vector. If you are interested in learning about the knot vector, have a look at this video.

Non-uniform B-splines
A property of the Bernstein polynomials is that when looking at the different S-spline Bézier parts, the path length of every part is the same. (The path length is often called the travel time). As you can imagine, it can be useful to have B-splines whose Bézier parts have different path lengths. This can be achieved by weighting the different polynomials:

$$\quad c(t)=\sum_{k=0}^{N}d_{k}B_{k, D}(t)w_k $$

$$w_k$$ is hereby the weight of the $$k$$-th control point. When the weights are not equal, the B-spline is called non-uniform.

Especially when B-splines should be used for 3D modelling, normalized, non-uniform B-splines are necessary. The normalization is done by a division by the weighted basis functions. Thus when all $$w_k$$ are equal, we get a uniform B-spline, independent on the weight itself:

$$\quad c(t)=\cfrac{\sum_{k=0}^{N}d_{k}B_{k, D}(t)w_k}{\sum_{k=0}^{N}B_{k, D}(t)w_k} $$

These non-uniform and rational (because of the division) B-splines are often called NURBS. Looking at their formula, we see that they are in fact a B-spline with a weighted basis $$R_{k, D}(t)$$:

$$\quad c(t)=\sum_{k=0}^{N}d_{k}R_{k, D}(t) $$

whereas

$$\quad R_{k, D}=\cfrac{B_{k,D}(u)w_k}{\sum_{l=1}^N B_{l,D}(t)w_l} $$

Krzywe złożone w programie FreeCAD
FreeCAD offers to create uniform or non-uniform B-splines of any degree in 2D via the Sketcher workbench.

Creation
To create B-splines, go into a sketch and use the toolbar button. Then left-click to set a control point, move the mouse left-click to set the next control point and so on. Finally right-click to finish the definition and create the B-spline.

By default uniform cubic splines are created, except there are not enough control points to do this. So when you create a B-spline with only 2 control points, you get of course a spline that is single linear Bézier curve, for 3 control points you get a quadratic Bézier curve, first with 5 control points you get a cubic B-spline consisting of 2 Bézier segments.

To create periodic B-splines (B-splines that form a closed curve), use the toolbar button. It is not necessary to set the last control point onto the first one because the B-spline will automatically be closed:



B-splines can also be generated out of existing sketch segments. To do this, select the elements and press the the toolbar button.

Zmiana ztopni
To change the degree, select the B-spline and use either the toolbar button or.

Note: Decreasing the degree cannot revert a prior increase of the degree, see the Wiki page Decrease B-spline degree for an explanation.

Zmiana wielokrotności węzłów
The points where two Bézier curves are connected to form the B-spline are called knots. The knot multiplicity determines how the Bézier parts are connected, see the Wiki page Increase knot multiplicity for details.

To change the knot multiplicity, use the toolbar buttons or.

Note: Creating two B-Splines that are connected to each other will not unite to a single new B-spline. So their connection point is not a knot. The only way to get a new knot in an existing B-spline is to decrease the degree. However, you may get many new knots. Thus the better choice is to redraw the B-spline with more control points.

Zmiana wagi
Around every control point you see a dark yellow circle. Its radius sets the weight for the corresponding control point. By default all circles have the radius 1. This is indicated with a radius constraint for the first control point circle.

To create a non-uniform B-spline the weights have to be non-uniform. To achieve that you can either change the radius constraint of the first control point circle:



or you delete the constraint that all circles are equal and then set different radius constraints for the circles.

If no radius constraint is set, you can also change the radius by dragging:



In the dragging example you see that a high weight attracts the curve to the control point while a very low weight changes the curve so as if the control point does almost not exist.

When you look at the creation function for non-uniform rational B-splines you see that a weight of zero would lead to a division by zero. Therefore you can only specify weights greater than zero.

Wyświetlanie informacji
Since the form of a B-spline does not tell much about its properties, FreeCAD offers different tools to display the properties:

Ograniczenia
At the moment (FreeCAD 0.19) there are some limitations when using splines you should know:
 * 1) You cannot set tangential constraints. In this example Sketcher_spline-limit-tangential.png you want to assure that the spline touches the blue curve 2 times tangentially. This would be useful because the blue line could for example be the spatial border for your design.
 * 2) You cannot insert a new control point between two selected existing control points. There is no other way than to redraw the spline.
 * 3) You cannot delete a control point. Also in this case you must redraw the spline
 * 4) You cannot create an offset curve for a B-spline using the tool Draft Offset.

Przypadki typowego zastosowania
According to the properties of B-splines, there are 3 main use cases:
 * 1) Curves that start/end tangentially to a certain direction. An example for this is the motivation example above.
 * 2) Curves describing larger designs and providing the freedom of local changes. See this example below.
 * 3) Curves providing a certain continuity (derivative). See this example below.

Projektowanie
Rozważmy przypadek, w którym projektujemy obudowę baterii kuchennej. Jej pożądany kształt powinien wyglądać tak jak ten:



Do zdefiniowania formy zewnętrznej korzystne jest użycie krzywej złożonej, ponieważ po zmianie punktu kontrolnego w celu zmiany krzywizny u dołu, krzywizna z boku i u góry nie ulegnie zmianie:



Continuity at Geometric Transitions
There are several cases where it is physically necessary to have a certain surface continuity at geometric transitions. Take for example the inner walls of a fluid channel. When you have a change in the diameter of the channel, you don't want to have an edge because edges would introduce turbulences. Therefore, like in the motivation example above, one uses splines for this purpose.

The development of the Bézier curves was initially triggered by the French car industry. Besides the saving of material and the reduction of the air flow drag, the look of the cars should also be improved. And when you look at the fancy design of French cars from the 60's and 70's you see that the Bézier curves gave car design a boost.

Let's take for example this task in the design of cars: The car fender should "look nice". Here is a basic sketch of our task:



"Looking nice" means that the (potential) customer looks at the fender and does not see unexpected light reflections and also no sudden changes in the reflection from the automotive paint at all. So what do you need to avoid changes in the reflections? Looking closely to the fender:



you see when there is an edge, there is a spatial area where the reflected light has less intensity and this is what you will notice when looking at the fender. To avoid this you need a continuous change in the slope of your surface elements. The slope is the first order derivative and as explained in section Basics, a second degree (quadratic) B-spline offers at every point a continuous first order derivative.

But is this really sufficient? At the point of geometric transition we have now at both sides the same slope, but the slope might change differently at both sides. Then we have this situation:



So we have also spatial areas in which the intensity of reflected light is different. To avoid this, we need at the geometrical point of transition also a continuity of the second order derivative and thus a cubic B-spline.