三点和四点贝塞尔及切线算法
//三点贝塞尔
Vector3 GetPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2)
{
t = Mathf.Clamp01(t);
float s= 1f - t;
return s * s * p0 + 2f * s * t * p1 + t * t * p2;
}
//三点切线
Vector3 GetTangent(float t, Vector3 p0, Vector3 p1, Vector3 p2)
{
t = Mathf.Clamp01(t);
return 2f * (1f - t) * (p1 - p0) + 2f * t * (p2 - p1);
}
//四点贝塞尔
Vector3 GetPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
{
t = Mathf.Clamp01(t);
float s= 1f - t;
return s * s * s * p0 + 3f * s * s * t * p1 + 3f * s * t * t * p2 + t * t * t * p3;
}
//四点切线
Vector3 GetTangent(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
{
t = Mathf.Clamp01(t);
float s= 1f - t;
return 3f * s * s * (p1 - p0) + 6f * s * t * (p2 - p1) + 3f * t * t * (p3 - p2);
}