# 贝赛尔曲线

## 原理

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

以二阶为例

**已知不共线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](/files/-M6B1kx0B_F5Qu64VVcg)

$$(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](/files/-M6B1kx1RbO_nyquP8uC)

$$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](/files/-M6B1kx2mocOvJXvLNql)

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

$$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](/files/-M6B1kx4tj6lr3uQ768A)

![Untitled/oczotc316x.gif](/files/-M6B1kx3P5LYULE8s-Nh)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://keenv.gitbook.io/notes/bezier-curve.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
