using System.Diagnostics; using System.Numerics; public class BezierUtils2 { /// /// 根据T值,计算贝塞尔曲线上面相对应的点 /// /// T值 /// 起始点 /// 控制点 /// 目标点 /// 根据T值计算出来的贝赛尔曲线点 private static 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; } /// /// 获取存储贝塞尔曲线点的数组 /// /// 起始点 /// 控制点 /// 目标点 /// 采样点的数量 /// 存储贝塞尔曲线点的数组 public static Vector3[] GetBeizerList(Vector3 startPoint, Vector3 controlPoint, Vector3 endPoint, int segmentNum) { Vector3[] path = new Vector3[segmentNum]; for (int i = 1; i <= segmentNum; i++) { float t = i / (float)segmentNum; Vector3 pixel = CalculateCubicBezierPoint(t, startPoint, controlPoint, endPoint); path[i - 1] = pixel; // Debug.Log(path[i - 1]); } return path; } }