Skip to content

Commit 7142f50

Browse files
authored
Merge pull request #283 from longo-andrea/article/bezier-curve
Bezier curve
2 parents f0c9488 + 5af805b commit 7142f50

File tree

1 file changed

+85
-87
lines changed

1 file changed

+85
-87
lines changed

7-animation/1-bezier-curve/article.md

Lines changed: 85 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,201 +1,199 @@
1-
# Bezier curve
1+
# Curve di Bezier
22

3-
Bezier curves are used in computer graphics to draw shapes, for CSS animation and in many other places.
3+
Le curve di Bezier sono utilizzate in computer grafica per disegnare forme, per animazioni CSS ed in molti altri posti.
44

5-
They are a very simple thing, worth to study once and then feel comfortable in the world of vector graphics and advanced animations.
5+
Sono veramente molto semplici, vale la pena studiarle per poi trovarsi a proprio agio nel mondo della grafica vettoriale e con animazioni avanzate.
66

7-
## Control points
7+
## Punti di controllo
88

9-
A [bezier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) is defined by control points.
9+
Una [curva di Bezier](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) è composta da punti di controllo.
1010

11-
There may be 2, 3, 4 or more.
11+
Possono essercene 2, 3, 4 o più.
1212

13-
For instance, two points curve:
13+
Ad esempio, una curva a due punti:
1414

1515
![](bezier2.svg)
1616

17-
Three points curve:
17+
Una curva a tre punti:
1818

1919
![](bezier3.svg)
2020

21-
Four points curve:
21+
Una curva a quattro punti:
2222

2323
![](bezier4.svg)
2424

25-
If you look closely at these curves, you can immediately notice:
25+
Guardando da vicino queste curve, possiamo subito notare:
2626

27-
1. **Points are not always on curve.** That's perfectly normal, later we'll see how the curve is built.
28-
2. **The curve order equals the number of points minus one**.
29-
For two points we have a linear curve (that's a straight line), for three points -- quadratic curve (parabolic), for four points -- cubic curve.
30-
3. **A curve is always inside the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of control points:**
27+
1. **I punti non sono sempre nella curva.** Questo è perfettamente normale, più avanti vedremo come viene costruita la curva.
28+
2. **Il grado della curva equivale al numero di punti meno uno**.
29+
Con due punti avremo una curva lineare (una retta), con tre punti, avremo una curva di grado due (una parabola), con quattro punti, avremo una curva di grado tre.
30+
3. **Una curva è sempre definita internamente all'[inviluppo convesso](https://en.wikipedia.org/wiki/Convex_hull) dei punti di controllo:**
3131

3232
![](bezier4-e.svg) ![](bezier3-e.svg)
3333

34-
Because of that last property, in computer graphics it's possible to optimize intersection tests. If convex hulls do not intersect, then curves do not either. So checking for the convex hulls intersection first can give a very fast "no intersection" result. Checking the intersection of convex hulls is much easier, because they are rectangles, triangles and so on (see the picture above), much simpler figures than the curve.
34+
Proprio grazie a quest'ultima proprietà, in computer grafica è possibile ottimizzare i test di intersezione. Se due inviluppi convessi non si intersecano, allora neanche le curve lo fanno. Quindi le verifiche sugli inviluppi convessi possono dare degli esiti più rapidi nella verifica della "non intersezione". La verifica di intersezione tra inviluppi convessi è molto più semplice, poiché questi sono rettangoli, triangoli e cosi via (vedi la figura sopra), le quali sono figure molto più semplici rispetto alle curve.
3535

36-
**The main value of Bezier curves for drawing -- by moving the points the curve is changing *in intuitively obvious way*.**
36+
**In grafica, ll principale vantaggio delle curve di Bezier è che muovendo i punti, le curve cambiano *in maniera piuttosto intuitiva*.**
3737

38-
Try to move control points using a mouse in the example below:
38+
Provate a giocare con i punti di controllo in questo esempio:
3939

4040
[iframe src="demo.svg?nocpath=1&p=0,0,0.5,0,0.5,1,1,1" height=370]
4141

42-
**As you can notice, the curve stretches along the tangential lines 1 -> 2 and 3 -> 4.**
42+
**Come puoi notare, la curva si estende lungo le linee tangenziali 1 -> 2 e 3 -> 4.**
4343

44-
After some practice it becomes obvious how to place points to get the needed curve. And by connecting several curves we can get practically anything.
44+
Dopo aver fatto un po' di pratica diventa ovvio come posizionare i punti per ottenere la curva desiderata. E connettendo diverse curve possiamo ottenere praticamente qualsiasi cosa.
4545

46-
Here are some examples:
46+
Qui vediamo alcuni esempi:
4747

4848
![](bezier-car.svg) ![](bezier-letter.svg) ![](bezier-vase.svg)
4949

50-
## De Casteljau's algorithm
50+
## L'algoritmo di De Casteljau's
5151

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) is identical to the mathematical definition and visually shows how it is constructed.
52+
Esiste una formula matematica per la definizione delle curve di Bezier, ma la vederemo tra un po', perché [l'algoritmo di De Casteljau's](https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm) è identico e dimostra a livello visivo come vengono definite.
5453

55-
First let's see the 3-points example.
54+
Come prima cosa, vediamo l'esempio con 3 punti.
5655

57-
Here's the demo, and the explanation follow.
56+
Qui vediamo la dimostrazione, seguita dalla spiegazione.
5857

59-
Control points (1,2 and 3) can be moved by the mouse. Press the "play" button to run it.
58+
I punti di controllo (1,2 e 3) possono essere mossi utilizzando il mouse. Premete il pulsante "Play" per avviare l'esempio.
6059

6160
[iframe src="demo.svg?p=0,0,0.5,1,1,0&animate=1" height=370]
6261

63-
**De Casteljau's algorithm of building the 3-point bezier curve:**
62+
**L'algoritmo di De Casteljau's per la costruzione di una curva di Bezier a 3 punti:**
6463

65-
1. Draw control points. In the demo above they are labeled: `1`, `2`, `3`.
66-
2. Build segments between control points 1 -> 2 -> 3. In the demo above they are <span style="color:#825E28">brown</span>.
67-
3. The parameter `t` moves from `0` to `1`. In the example above the step `0.05` is used: the loop goes over `0, 0.05, 0.1, 0.15, ... 0.95, 1`.
64+
1. Traccia i punti di controllo. Nella dimostrazione vista sopra, questi sono etichettati come: `1`, `2`, `3`.
65+
2. Traccia le semirette che congiungono i punti di controllo 1 -> 2 -> 3. Nella dimostrazione vista sopra questi sono di colore <span style="color:#825E28">marrone</span>.
66+
3. Il parametro `t` passa da `0` a `1`. Nell'esempio sopra questo cresce con passi di `0.05`: il ciclo esegue `0, 0.05, 0.1, 0.15, ... 0.95, 1`.
6867

69-
For each of these values of `t`:
68+
Per ognuno dei valori assunti da `t`:
7069

71-
- On each <span style="color:#825E28">brown</span> segment we take a point located on the distance proportional to `t` from its beginning. As there are two segments, we have two points.
70+
- Per ogni segmento <span style="color:#825E28">marrone</span> prendiamo un punto localizzato in maniera proporzionale fra `t` ed il suo inizio. Poiché ci sono due segmenti, avremo due punti.
7271

73-
For instance, for `t=0` -- both points will be at the beginning of segments, and for `t=0.25` -- on the 25% of segment length from the beginning, for `t=0.5` -- 50%(the middle), for `t=1` -- in the end of segments.
72+
Ad esempio, per `t=0`, entrambi i punti si troverano all'inizio del segmento, per `t=0.25`, si troveranno al 25% della lunghezza del segmento, per 50% (al centro), per `t=1`, alla fine del segmento.
7473

75-
- Connect the points. On the picture below the connecting segment is painted <span style="color:#167490">blue</span>.
74+
- Collega i punti. Nella figura sotto, i segmenti collegati sono colorati di <span style="color:#167490">blu</span>.
7675

7776

7877
| For `t=0.25` | For `t=0.5` |
7978
| ------------------------ | ---------------------- |
8079
| ![](bezier3-draw1.svg) | ![](bezier3-draw2.svg) |
8180

82-
4. Now in the <span style="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 <span style="color:red">red</span>.
81+
4. Ora nel segmento <span style="color:#167490">blu</span>, prende un punto alla stessa distanza proporzionale `t`. Quindi, per `t=0.25` (immagine a sinistra) avremo un punto alla fine del quarto sinistro del segmento, per `t=0.5` (la figura di destra), lo avremo a metà del segmento. Nelle figure sopra, questo punto è <span style="color:red">rosso</span>.
8382

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.
83+
5. Poiché `t` viene valutato da `0` fino a `1`, ogni valore che assume, aggiunge un punto alla curva. L'insieme di questi punti definisce la curva di Bezier. Nella figura è la parabola rossa.
8584

86-
That was a process for 3 points. But the same is for 4 points.
85+
Quello appena descritto, è il processo che si applica per 3 punti. Ma il procedimento è uguale anche con 4 punti.
8786

88-
The demo for 4 points (points can be moved by a mouse):
87+
Qui vediamo la dimostrazione con 4 punti (i punti possono essere mossi utilizzando il mouse):
8988

9089
[iframe src="demo.svg?p=0,0,0.5,0,0.5,1,1,1&animate=1" height=370]
9190

92-
The algorithm for 4 points:
91+
L'algoritmo applicato per 4 punti:
9392

94-
- Connect control points by segments: 1 -> 2, 2 -> 3, 3 -> 4. There will be 3 <span style="color:#825E28">brown</span> segments.
95-
- For each `t` in the interval from `0` to `1`:
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 <span style="color:#0A0">green segments</span>.
97-
- On these segments we take points proportional to `t`. We get one <span style="color:#167490">blue segment</span>.
98-
- On the blue segment we take a point proportional to `t`. On the example above it's <span style="color:red">red</span>.
99-
- These points together form the curve.
93+
- Connette i punti di controllo con i segmenti: 1 -> 2, 2 -> 3, 3 -> 4. Ci saranno 3 segmenti <span style="color:#825E28">marrone</span>.
94+
- Per ogni valore di `t` nell'intervallo da `0` a `1`:
95+
- Tracciamo i punti nel segmento ad una distanza `t` partendo dall'inizio. Questi punti vengono connessi, in questo modo avremo due <span style="color:#0A0">segmenti verdi</span>.
96+
- Su questi segmenti, tracciamo i punti in base al valore di `t`. Avremo cosi un <span style="color:#167490">segmento blu</span>.
97+
- Nel segmento blu, tracciamo un punto in base al valore di `t`. Nell'esempio sopra è <span style="color:red">rosso</span>.
98+
- L'insieme di questi punti forma la curva.
10099

101-
The algorithm is recursive and can be generalized for any number of control points.
100+
L'algoritmo è ricorsivo, e può essere quindi generalizzato per un qualsiasi numero di punti di controllo.
102101

103-
Given N of control points:
102+
Dato un numero N di punti di controllo:
104103

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.
104+
1. Li colleghiamo per ottenere i primi N-1 segmenti.
105+
2. Successivamente, per ogni valore di `t` nell'intervallo `0`-`1`, tracciamo un punto su ogni segmento ad una distanza `t` e li colleghiamo. Avremo cosi N-2 segmenti.
106+
3. Ripetiamo il passaggio 2, fino a rimanere con un solo punto.
108107

109-
These points make the curve.
108+
I punti ottenuti definiscono la curva.
110109

111110
```online
112-
**Run and pause examples to clearly see the segments and how the curve is built.**
111+
**Esegui e metti in pausa gli esempi per vedere con più chiarezza i segmenti e come vengono costruite le curve.**
113112
```
114113

115114

116-
A curve that looks like `y=1/t`:
115+
La curva equivalente alla formula `y=1/t`:
117116

118117
[iframe src="demo.svg?p=0,0,0,0.75,0.25,1,1,1&animate=1" height=370]
119118

120-
Zig-zag control points also work fine:
119+
Anche i punti di controllo a zig-zag funzionano:
121120

122121
[iframe src="demo.svg?p=0,0,1,0.5,0,0.5,1,1&animate=1" height=370]
123122

124-
Making a loop is possible:
123+
E' anche possibile definire un cappio:
125124

126125
[iframe src="demo.svg?p=0,0,1,0.5,0,1,0.5,0&animate=1" height=370]
127126

128-
A non-smooth Bezier curve (yeah, that's possible too):
127+
Una curva di Bezier acuta (certo, è possibile fare anche questo):
129128

130129
[iframe src="demo.svg?p=0,0,1,1,0,1,1,0&animate=1" height=370]
131130

132131
```online
133-
If there's something unclear in the algorithm description, please look at the live examples above to see how
134-
the curve is built.
132+
Se c'è ancora qualcosa di poco chiaro riguardo l'algoritmo descritto, riguardate gli esempi interattivi visti sopra, per capire come viene costruita la curva.
135133
```
136134

137-
As the algorithm is recursive, we can build Bezier curves of any order, that is: 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.
135+
Poiché l'algoritmo è ricorsivo, possiamo definire curve di Bezier di qualsiasi grado, ad esempio utilizzando 5,6 o più punti di controllo. Ma nella pratica l'utilizzo di molti punti è poco utile. Solitamente 2-3 punti sono più che sufficienti, è sempre possibile unire diverse curve per ottenerne di più complesse. In questo modo lo sviluppo ed i calcoli non si complicheranno troppo.
138136

139-
```smart header="How to draw a curve *through* given points?"
140-
To specify a Bezier curve, control points are used. As we can see, they are not on the curve, except the first and the last ones.
137+
```smart header="Come tracciare una curva con i punti forniti?"
138+
Per definire una curva di Bezier, vengono utilizzando i punti di controllo. Come abbiamo visto, questi non sono all'interno della curva stessa, ad eccezione del primo ed ultimo.
141139
142-
Sometimes we have another task: to draw a curve *through several points*, so that all of them are on a single smooth curve. That task is called [interpolation](https://en.wikipedia.org/wiki/Interpolation), and here we don't cover it.
140+
Talvolta abbiamo un altro compito: tracciare una curva *attraverso molti punti*, cosicché questi vadano a formare una curva "morbida".. Questa attività è definita [interpolazione](https://en.wikipedia.org/wiki/Interpolation), ma non la vedremo qui.
143141
144-
There are mathematical formulas for such curves, for instance [Lagrange polynomial](https://en.wikipedia.org/wiki/Lagrange_polynomial). In computer graphics [spline interpolation](https://en.wikipedia.org/wiki/Spline_interpolation) is often used to build smooth curves that connect many points.
142+
Esistono delle formule matematiche per questo tipo di curve, ad esempio il [polinomio di Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial). In computer grafica viene utilizzata spesso la [spline interpolation](https://en.wikipedia.org/wiki/Spline_interpolation), per costruire curve più "morbide" connettendo molti punti.
145143
```
146144

147145

148-
## Maths
146+
## Matematica
149147

150-
A Bezier curve can be described using a mathematical formula.
148+
Una curva di Bezier può essere descritta utilizzando una formula matematica.
151149

152-
As we saw -- there's actually no need to know it, most people just draw the curve by moving points with a mouse. But if you're into maths -- here it is.
150+
Come abbiamo visto, non c'è alcun bisogno di conoscerla, la maggior parte degli sviluppatori tracciano le curve selezionando i punti di controllo con il mouse. Ma se vi interessa il lato matematico, eccovi accontentati.
153151

154-
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]`.
152+
Date le coordinate dei punti di controllo <code>P<sub>i</sub></code>: il primo punto di controllo ha coordinate <code>P<sub>1</sub> = (x<sub>1</sub>, y<sub>1</sub>)</code>, il secondo: <code>P<sub>2</sub> = (x<sub>2</sub>, y<sub>2</sub>)</code>, e cosi via, le coordinate della curva sono descritte dall'equazione dipendente da `t` nell'intervallo `[0,1]`.
155153

156-
- The formula for a 2-points curve:
154+
- La formula per una curva a 2 punti:
157155

158156
<code>P = (1-t)P<sub>1</sub> + tP<sub>2</sub></code>
159-
- For 3 control points:
157+
- Per 3 punti di controllo:
160158

161159
<code>P = (1−t)<sup>2</sup>P<sub>1</sub> + 2(1−t)tP<sub>2</sub> + t<sup>2</sup>P<sub>3</sub></code>
162-
- For 4 control points:
160+
- Per 4 punti di controllo:
163161

164162
<code>P = (1−t)<sup>3</sup>P<sub>1</sub> + 3(1−t)<sup>2</sup>tP<sub>2</sub> +3(1−t)t<sup>2</sup>P<sub>3</sub> + t<sup>3</sup>P<sub>4</sub></code>
165163

166164

167-
These are vector equations. In other words, we can put `x` and `y` instead of `P` to get corresponding coordinates.
165+
Queste sono equazioni vettoriali. In altre parole, possiamo utilizzare i valori `x` ed `y` piuttosto di `P` per ottenere le coordinate corrispondenti.
168166

169-
For instance, the 3-point curve is formed by points `(x,y)` calculated as:
167+
Ad esempio, la curva a 3 punti è formata dai punti `(x,y)` calcolati come:
170168

171169
- <code>x = (1−t)<sup>2</sup>x<sub>1</sub> + 2(1−t)tx<sub>2</sub> + t<sup>2</sup>x<sub>3</sub></code>
172170
- <code>y = (1−t)<sup>2</sup>y<sub>1</sub> + 2(1−t)ty<sub>2</sub> + t<sup>2</sup>y<sub>3</sub></code>
173171

174-
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.
172+
Piuttosto di <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> dovremo inserire le coordinate di 3 punti di controllo, e successivamente, mentre `t` si sposta nell'intervallo `0`-`1`, per ogni valore di `t` avremo il corrispondente `(x,y)` della curva.
175173

176-
For instance, if control points are `(0,0)`, `(0.5, 1)` and `(1, 0)`, the equations become:
174+
Ad esempio, se i punti di controllo sono `(0,0)`, `(0.5, 1)` e `(1, 0)`, le corrispondenti equazioni saranno:
177175

178176
- <code>x = (1−t)<sup>2</sup> * 0 + 2(1−t)t * 0.5 + t<sup>2</sup> * 1 = (1-t)t + t<sup>2</sup> = t</code>
179177
- <code>y = (1−t)<sup>2</sup> * 0 + 2(1−t)t * 1 + t<sup>2</sup> * 0 = 2(1-t)t = –2t<sup>2</sup> + 2t</code>
180178

181-
Now as `t` runs from `0` to `1`, the set of values `(x,y)` for each `t` forms the curve for such control points.
179+
Ora, mentre `t` cresce da `0` a `1`, l'insieme dei valori `(x,y)` per ogni `t` definirà la curva per quel punto di controllo.
182180

183-
## Summary
181+
## Riepilogo
184182

185-
Bezier curves are defined by their control points.
183+
Le curve di Bezier sono definite da punti di controllo.
186184

187-
We saw two definitions of Bezier curves:
185+
Abbiamo visto due definizioni delle curve di Bezier:
188186

189-
1. Using a drawing process: De Casteljau's algorithm.
190-
2. Using a mathematical formulas.
187+
1. Utilizzando un algoritmo: l'algoritmo di De Casteljau's.
188+
2. Utilizzando una formula matematica.
191189

192-
Good properties of Bezier curves:
190+
Le curve di Bezier hanno delle ottime proprietà, tra cui:
193191

194-
- We can draw smooth lines with a mouse by moving control points.
195-
- Complex shapes can be made of several Bezier curves.
192+
- Possiamo definire delle curve "morbide" con il semplice utilizzo del mouse, spostando i punti di controllo.
193+
- Forme complesse possono essere ottenute mettendo insieme più curve di Bezier.
196194

197-
Usage:
195+
Utilizzo:
198196

199-
- In computer graphics, modeling, vector graphic editors. Fonts are described by Bezier curves.
200-
- In web development -- for graphics on Canvas and in the SVG format. By the way, "live" examples above are written in SVG. They are actually a single SVG document that is given different points as parameters. You can open it in a separate window and see the source: [demo.svg](demo.svg?p=0,0,1,0.5,0,0.5,1,1&animate=1).
201-
- In CSS animation to describe the path and speed of animation.
197+
- In computer grafica, modellazione, ed editor di grafica vettoriale. I font sono descritti tramite curve di Bezier.
198+
- Nello sviluppo web, per la grafica su Canvas e nel formato SVG. Comunque, gli esempi interattivi visti sopra sono scritti in SVG. In realtà sono un unico documento SVG che accetta diversi punti come parametri. Potete aprirli una finestra separata e vederne il codice sorgente: [demo.svg](demo.svg?p=0,0,1,0.5,0,0.5,1,1&animate=1).
199+
- Nelle animazioni CSS per descrivere il percorso e la velocità dell'animazione.

0 commit comments

Comments
 (0)