ソースコード
using UnityEngine;
<summary>
</summary>
public static class MathfUtils
{
<summary>
</summary>
<remarks></remarks>
<param name="x1"></param>
<param name="x2"></param>
<param name="x3"></param>
<param name="x4"></param>
<param name="t"></param>
<returns></returns>
public static float BezierCurveX(float x1, float x2, float x3, float x4, float t)
{
return Mathf.Pow(1 - t, 3) * x1 + 3 * Mathf.Pow(1 - t, 2) * t * x2 + 3 * (1 - t) * Mathf.Pow(t, 2) * x3 + Mathf.Pow(t, 3) * x4;
}
<summary>
</summary>
<remarks></remarks>
<param name="y1"></param>
<param name="y2"></param>
<param name="y3"></param>
<param name="y4"></param>
<param name="t"></param>
<returns></returns>
public static float BezierCurveY(float y1, float y2, float y3, float y4, float t)
{
return Mathf.Pow(1 - t, 3) * y1 + 3 * Mathf.Pow(1 - t, 2) * t * y2 + 3 * (1 - t) * Mathf.Pow(t, 2) * y3 + Mathf.Pow(t, 3) * y4;
}
<summary>
</summary>
<param name="p1"></param>
<param name="p2"></param>
<param name="p3"></param>
<param name="p4"></param>
<param name="t"></param>
<returns></returns>
public static Vector2 BezierCurve(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t)
{
return new Vector2(
BezierCurveX(p1.x, p2.x, p3.x, p4.x, t),
BezierCurveY(p1.y, p2.y, p3.y, p4.y, t));
}
}
関連記事