0%

贝塞尔曲线

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class BezierTool
{
/// <summary>
/// 二次贝塞尔曲线
/// 公式:(1-t)^2*P0+ 2*(1-t) tP1 + t^2*P2
/// </summary>
public static Vector3 BezierMath2(Vector3 p0, Vector3 p1, Vector3 p2, float t)
{
return (1 - t) * (1 - t) * p0 + 2 * (1 - t) * t * p1 + t * t * p2;
}


// 三次贝塞尔
public static Vector3 Bezier_3(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
return (1 - t) * ((1 - t) * ((1 - t) * p0 + t * p1) + t * ((1 - t) * p1 + t * p2)) + t * ((1 - t) * ((1 - t) * p1 + t * p2) + t * ((1 - t) * p2 + t * p3));
}
}