I’m using Bezier curves for gameobject placement. Mostly it’s enough to use cubic curve but in some cases I need more precision.
I’m not strong in math, so I found 5th order equation in wiki and the curve looks fine. Now I just need set angles. Can anyone help me with tangent equation for 5th order Bezier curve?
[1]:
//Cubic
public Vector3 GetPosition(float t)
{
return (1 - t) * (1 - t) * (1 - t) * _p0
+ 3 * (1 - t) * (1 - t) * t * _p1
+ 3 * (1 - t) * t * t * _p2
+ t * t * t * _p3;
}
public Vector3 GetTangent(float t)
{
float u = 1 - t;
float uu = u * u;
float tu = t * u;
float tt = t * t;
Vector3 P = _p0 * 3 * uu * (-1.0f);
P += _p1 * 3 * (uu - 2 * tu);
P += _p2 * 3 * (2 * tu - tt);
P += _p3 * 3 * tt;
return P.normalized;
}
//n5
public Vector3 GetPosition(float t)
{
float u = 1 - t;
float uu = u * u;
float uuu = uu * u;
float tt = t * t;
float ttt = t * tt;
Vector3 P = _p0 * uu * uuu;
P += _p1 * 5 * uu * uu * t;
P += _p2 * 10 * uuu * tt;
P += _p3 * 10 * ttt * uu;
P += _p4 * 5 * tt * tt * u;
P += _p5 * ttt * tt;
return P;
}