2021-10-17 18:26:00 +02:00
|
|
|
|
---
|
2021-12-27 14:58:44 +01:00
|
|
|
|
title: Understanding Bézier curves
|
2021-08-25 16:09:31 +02:00
|
|
|
|
order: 50
|
2021-10-17 18:26:00 +02:00
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
|
While lines on computers are easy to store with a start and end point,
|
2021-08-25 16:09:31 +02:00
|
|
|
|
curves require more information.
|
2021-12-27 14:58:44 +01:00
|
|
|
|
In FreeSewing — as in SVG and countless of other computer applications —
|
2022-02-19 08:04:25 +01:00
|
|
|
|
curves are stored as [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve),
|
|
|
|
|
named after French engineer [Pierre Bézier](https://en.wikipedia.org/wiki/Pierre_B%C3%A9zier) who
|
2021-12-27 14:58:44 +01:00
|
|
|
|
popularized their use back in the 1960s.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
2021-12-27 14:58:44 +01:00
|
|
|
|
In FreeSewing, we use so-called cubic Bézier curves which have:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
|
- A start point
|
|
|
|
|
- A first control point that’s linked to the start point
|
|
|
|
|
- A second control point that’s linked to the end point
|
|
|
|
|
- An end point
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
2022-10-12 00:25:06 +02:00
|
|
|
|
<Example caption="An example of a Bézier curve drawn by the Path.curve() method" settings="margin: 20">
|
|
|
|
|
```js
|
|
|
|
|
({ Point, points, Path, paths, part }) => {
|
|
|
|
|
|
|
|
|
|
points.from = new Point(10, 20)
|
|
|
|
|
points.cp1 = new Point(40, 0)
|
|
|
|
|
points.cp2 = new Point(60, 40)
|
|
|
|
|
points.to = new Point(90, 20)
|
|
|
|
|
|
|
|
|
|
paths.line = new Path()
|
|
|
|
|
.move(points.from)
|
|
|
|
|
.curve(points.cp1, points.cp2, points.to)
|
|
|
|
|
.setText("Path.curve()", "text-sm center fill-note")
|
|
|
|
|
|
|
|
|
|
return part
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-12-27 14:58:44 +01:00
|
|
|
|
</Example>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
2022-02-20 14:35:50 +01:00
|
|
|
|
Bézier curves and their _handles_ or _control points_ are surprisingly intuitive.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
The following illustration does a great job at explaining how they are constructed:
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2022-12-25 21:13:48 -08:00
|
|
|
|
You don't need to understand the mathematics behind Bézier Curves.
|
2022-02-20 14:35:50 +01:00
|
|
|
|
As long as you intuitively _get_ how the control points influence the curve, you're good to go.
|
2021-12-27 14:58:44 +01:00
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
|
<Note>
|
|
|
|
|
|
|
|
|
|
###### More on Bézier curves
|
|
|
|
|
|
2022-08-27 21:49:14 +02:00
|
|
|
|
Wikipedia has a good [introduction to Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve).
|
2022-02-19 08:04:25 +01:00
|
|
|
|
For a deep-dive into the subject, check out [A Primer on Bézier Curves](https://pomax.github.io/bezierinfo/) by
|
2021-12-27 14:58:44 +01:00
|
|
|
|
[Pomax](https://github.com/Pomax).
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
|
|
</Note>
|