# 贝赛尔曲线

## 原理

贝塞尔曲线由起点、终点(也称锚点)和若干个控制点决定

以二阶为例

**已知不共线3点A、B、C，依次连接线段AB、BC，分别取AB、BC中D、E，使得AD:AB = BE:BC，连接DE，取DE上F，使得DF:DE = AD:AB = BE:BC。利用极限知识，让D点从A移动到B，找到所有的F点，这些点形成的曲线便是贝塞尔曲线。**

一条曲线可在任意点切割成两条或任意多条子曲线，每一条子曲线仍是贝塞尔曲线

n阶贝塞尔曲线可以看成二阶贝塞尔曲线组成

PS中的钢笔通过锚点来绘制曲线

## 公式

引入参数t，t满足区间\[0, 1]，t的取值代表比例，**DF:DE = AD:AB = BE:BC = t。**

$$P\_0B\_t ： P\_0P\_1 = t$$

### 一阶贝塞尔曲线

![Untitled/0d32hcuk7z.gif](https://914534613-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fnotes%2F-M6B0ZpZ_qXuHw04ZAuX%2F-M6B1kx0B_F5Qu64VVcg%2F0d32hcuk7z.gif?generation=1588266209725436\&alt=media)

$$(B\_t - P\_0) / (P\_1 - P\_0) = t$$

根据以上公式可得

$$B\_t = P\_0 + (P\_1 - P\_0)t = (1 - t)P\_0 + tP\_1 (1)$$

### 二阶贝塞尔曲线

![Untitled/54diwjdj8b.gif](https://914534613-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fnotes%2F-M6B0ZpZ_qXuHw04ZAuX%2F-M6B1kx1RbO_nyquP8uC%2F54diwjdj8b.gif?generation=1588266209725624\&alt=media)

$$B\_a = P\_0 + (P\_1 - P\_0)t = (1 - t)P\_0 + tP\_1 (2)$$

$$B\_b = P\_1 + (P\_2 - P\_1)t = (1 - t)P\_1 + tP\_2 (3)$$

$$B\_t = P\_a + (P\_b - P\_a)t = (1 - t)P\_a + tP\_b (4)$$

将公式(2)(3)代入公式(4)中，可得

$$P\_t = (1-t)P\_a + tP\_b = (1-t)\[(1-t)P\_0 + tP\_1] + t\[(1-t)P\_1 + tP\_2] = (1-t)^2P\_0 + 2(1-t)tP\_1 + t^2P\_2 (5)$$

### 三阶贝塞尔曲线

![Untitled/mhmuin6c2w.gif](https://914534613-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fnotes%2F-M6B0ZpZ_qXuHw04ZAuX%2F-M6B1kx2mocOvJXvLNql%2Fmhmuin6c2w.gif?generation=1588266209724752\&alt=media)

同理，根据以上的推导过程可得

$$P\_a = P\_0 + (P\_1 - P\_0)t = (1 - t)P\_0 + tP\_1$$

$$P\_b = P\_1 + (P\_2 - P\_1)t = (1 - t)P\_1 + tP\_2$$

$$P\_c = P\_2 + (P\_3 - P\_2)t = (1 - t)P\_2 + tP\_3$$

$$P\_d = P\_a + (P\_b - P\_a)t = (1 - t)P\_a + tP\_b$$

$$P\_e = P\_b + (P\_c - P\_b)t = (1 - t)P\_b + tP\_c$$

由此可以推导

$$P\_t = P\_d + (P\_e - P\_d)t = (1 - t)P\_d + tP\_e = (1-t)\[(1 - t)P\_a + tP\_b] + t\[(1 - t)P\_b + tP\_c] = (1-t)^2P\_a + 2(1-t)tP\_b + t^2P\_c = (1-t)^2\[(1 - t)P\_0 + tP\_1] + 2(1-t)t\[(1 - t)P\_1 + tP\_2] + t^2\[(1 - t)P\_2 + tP\_3] = (1 - t)^3P\_0 + (1 - t)^2tP\_1 + 2t(1 - t)^2P\_1 + 2t^2(1-t)P\_2 + t^2(1-t)P\_2 + t^3P\_3 = (1-t)^3P\_0 + 3t(1-t)^2tP\_1 + 2t^2(1-t)P\_2 + t^3P\_3$$

### n阶贝塞尔曲线

![Untitled/qygaf0ua9b.gif](https://914534613-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fnotes%2F-M6B0ZpZ_qXuHw04ZAuX%2F-M6B1kx4tj6lr3uQ768A%2Fqygaf0ua9b.gif?generation=1588266209724575\&alt=media)

![Untitled/oczotc316x.gif](https://914534613-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fnotes%2F-M6B0ZpZ_qXuHw04ZAuX%2F-M6B1kx3P5LYULE8s-Nh%2Foczotc316x.gif?generation=1588266209754280\&alt=media)
