You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Bezier curve can be described using a mathematical formula.
53
-
54
-
As we'll see soon -- there's no need to know it. But for completeness -- here it is.
55
-
56
-
Given the coordinates of control points <code>P<sub>i</sub></code>: the first control point has coordinates <code>P<sub>1</sub> = (x<sub>1</sub>, y<sub>1</sub>)</code>, the second: <code>P<sub>2</sub> = (x<sub>2</sub>, y<sub>2</sub>)</code>, and so on, the curve coordinates are described by the equation that depends on the parameter `t` from the segment `[0,1]`.
Instead of <code>x<sub>1</sub>, y<sub>1</sub>, x<sub>2</sub>, y<sub>2</sub>, x<sub>3</sub>, y<sub>3</sub></code> we should put coordinates of 3 control points.
76
-
77
-
For instance, if control points are `(0,0)`, `(0.5, 1)` and `(1, 0)`, the equations are:
Now as `t` runs from `0` to `1`, the set of values `(x,y)` for each `t` forms the curve.
83
-
84
-
That's probably too scientific, not very obvious why curves look like that, and how they depend on control points.
85
-
86
-
So here's the drawing algorithm that may be easier to understand.
87
-
88
50
## De Casteljau's algorithm
89
51
90
-
[De Casteljau's algorithm](https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm) is identical to the mathematical definition of the curve, but visually shows how it is built.
52
+
There's a mathematical formula for Bezier curves, but let's cover it a bit later, because
53
+
[De Casteljau's algorithm](https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm) it is identical to the mathematical definition and visually shows how it is constructed.
91
54
92
-
Let's see it on the 3-points example.
55
+
First let's see the 3-points example.
93
56
94
57
Here's the demo, and the explanation follow.
95
58
@@ -116,19 +79,19 @@ Points can be moved by the mouse. Press the "play" button to run it.
4. Now the <spanstyle="color:#167490">blue</span> segment take a point on the distance proportional to the same value of `t`. That is, for `t=0.25` (the left picture) we have a point at the end of the left quarter of the segment, and for `t=0.5` (the right picture) -- in the middle of the segment. On pictures above that point is <spanstyle="color:red">red</span>.
82
+
4. Now in the <spanstyle="color:#167490">blue</span> segment take a point on the distance proportional to the same value of `t`. That is, for `t=0.25` (the left picture) we have a point at the end of the left quarter of the segment, and for `t=0.5` (the right picture) -- in the middle of the segment. On pictures above that point is <spanstyle="color:red">red</span>.
120
83
121
84
5. As `t` runs from `0` to `1`, every value of `t` adds a point to the curve. The set of such points forms the Bezier curve. It's red and parabolic on the pictures above.
122
85
123
86
That was a process for 3 points. But the same is for 4 points.
124
87
125
-
The demo for 4 points (points can be moved by mouse):
88
+
The demo for 4 points (points can be moved by a mouse):
-Control points are connected by segments: 1 -> 2, 2 -> 3, 3 -> 4. We have 3 <spanstyle="color:#825E28">brown</span> segments.
94
+
-Connect control points by segments: 1 -> 2, 2 -> 3, 3 -> 4. There will be 3 <spanstyle="color:#825E28">brown</span> segments.
132
95
- For each `t` in the interval from `0` to `1`:
133
96
- We take points on these segments on the distance proportional to `t` from the beginning. These points are connected, so that we have two <spanstyle="color:#0A0">green segments</span>.
134
97
- On these segments we take points proportional to `t`. We get one <spanstyle="color:#167490">blue segment</span>.
@@ -137,30 +100,37 @@ The algorithm:
137
100
138
101
The algorithm is recursive and can be generalized for any number of control points.
139
102
140
-
Given N of control points, we connect them to get initially N-1 segments.
103
+
Given N of control points:
104
+
105
+
1. We connect them to get initially N-1 segments.
106
+
2. Then for each `t` from `0` to `1`, we take a point on each segment on the distance proportional to `t` and connect them. There will be N-2 segments.
107
+
3. Repeat step 2 until there is only one point.
141
108
142
-
Then for each `t` from `0` to `1`:
143
-
- Take a point on each of segment on the distance proportional to `t` and connect them -- there will be N-2 segments.
144
-
- Take a point on each of these segments on the distance proportional to `t` and connect -- there will be N-3 segments, and so on...
145
-
- Till we have one point. These points make the curve.
109
+
These points make the curve.
110
+
111
+
```online
112
+
**Run and pause examples to clearly see the segments and how the curve is built.**
As the algorithm is recursive, we can build Bezier curves of any order: using 5, 6 or more control points. But in practice they are less useful. Usually we take 2-3 points, and for complex lines glue several curves together. That's simpler to develop and calculate.
133
+
As the algorithm is recursive, we can build Bezier curves of any order: using 5, 6 or more control points. But in practice many points are less useful. Usually we take 2-3 points, and for complex lines glue several curves together. That's simpler to develop and calculate.
164
134
165
135
```smart header="How to draw a curve *through* given points?"
166
136
We use control points for a Bezier curve. As we can see, they are not on the curve. Or, to be precise, the first and the last ones do belong to curve, but others don't.
@@ -172,6 +142,42 @@ There are mathematical formulas for such curves, for instance [Lagrange polynomi
172
142
In computer graphics [spline interpolation](https://en.wikipedia.org/wiki/Spline_interpolation) is often used to build smooth curves that connect many points.
173
143
```
174
144
145
+
146
+
## Maths
147
+
148
+
A Bezier curve can be described using a mathematical formula.
149
+
150
+
As we saw -- there's actually no need to know it. But for completeness -- here it is.
151
+
152
+
Given the coordinates of control points <code>P<sub>i</sub></code>: the first control point has coordinates <code>P<sub>1</sub> = (x<sub>1</sub>, y<sub>1</sub>)</code>, the second: <code>P<sub>2</sub> = (x<sub>2</sub>, y<sub>2</sub>)</code>, and so on, the curve coordinates are described by the equation that depends on the parameter `t` from the segment `[0,1]`.
Instead of <code>x<sub>1</sub>, y<sub>1</sub>, x<sub>2</sub>, y<sub>2</sub>, x<sub>3</sub>, y<sub>3</sub></code> we should put coordinates of 3 control points, and then as `t` moves from `0` to `1`, for each value of `t` we'll have `(x,y)` of the curve.
173
+
174
+
For instance, if control points are `(0,0)`, `(0.5, 1)` and `(1, 0)`, the equations become:
0 commit comments