/// <summary>
/// 获取存储贝塞尔曲线点的数组
/// </summary>
/// <param name="startPoint"></param>起始点
/// <param name="controlPoint"></param>控制点
/// <param name="endPoint"></param>目标点
/// <param name="segmentNum"></param>采样点的数量
/// <returns></returns>存储贝塞尔曲线点的数组
public Vector3[] GetBeizerList(Vector3 startPoint, Vector3 controlPoint, Vector3 endPoint, int segmentNum)//, float slopePeak, float offectValue
{
Vector3[] path = new Vector3[segmentNum+1];
path[0] = startPoint;
for (int i = 1; i <= segmentNum; i++)
{
float t = i / (float)segmentNum;
Vector3 pixel = CalculateCubicBezierPoint(t, startPoint, controlPoint, endPoint);
path[i] = pixel;
}
path[segmentNum] = endPoint;
return path;
}
1,二次贝尔赛曲线通过系数,开始点,中间点,目标点获取
private Vector3 CalculateCubicBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2)
{
float u = 1 - t;
float tt = t * t;
float uu = u * u;
Vector3 p = uu * p0;
p += 2 * u * t * p1;
p += tt * p2;
return p;
}
2,三次贝尔赛曲线通过系数,开始点,两个中间点,目标点获取
//获得贝塞尔曲线的数组
Vector3 CalculateCubicBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2,Vector3 p3)
{
float u = 1 - t;
float uu = u * u;
float uuu = u * u * u;
float tt = t * t;
float ttt = t * t * t;
Vector3 p = p0 * uuu;
p += 3 * p1 * t * uu;
p += 3 * p2 * tt * u;
p += p3 * ttt;
return p;
}
网友评论