VectorUtils.cs 1.3 KB

123456789101112131415161718192021222324252627282930
  1. namespace UnityEngine
  2. {
  3. public static class VectorUtils
  4. {
  5. /// <summary>
  6. /// 贝塞尔曲线坐标
  7. /// </summary>
  8. /// <param name="start">曲线的起始位置</param>
  9. /// <param name="center">决定曲线形状的控制点</param>
  10. /// <param name="end">曲线的终点</param>
  11. /// <param name="t">0到1的值,0获取曲线的起点,1获得曲线的终点</param>
  12. /// <returns></returns>
  13. public static Vector3 GetBezierPoint(Vector3 start, Vector3 center, Vector3 end, float t)
  14. {
  15. return (1 - t) * (1 - t) * start + 2 * t * (1 - t) * center + t * t * end;
  16. }
  17. /// <summary>
  18. /// 贝塞尔曲线坐标
  19. /// </summary>
  20. /// <param name="start">曲线的起始位置</param>
  21. /// <param name="center">决定曲线形状的控制点</param>
  22. /// <param name="end">曲线的终点</param>
  23. /// <param name="t">0到1的值,0获取曲线的起点,1获得曲线的终点</param>
  24. /// <returns></returns>
  25. public static Vector3 BezierPoint(this Vector3 start, Vector3 center, Vector3 end, float t)
  26. {
  27. return (1 - t) * (1 - t) * start + 2 * t * (1 - t) * center + t * t * end;
  28. }
  29. }
  30. }