public CurveVectors(CurveVectors vectors)
 {
     this.p0 = vectors.p0;
     this.p1 = vectors.p1;
     this.p2 = vectors.p2;
     this.p3 = vectors.p3;
 }
    public static Vector3 GetFirstDerivative(CurveVectors vectors, float t)
    {
        t = Mathf.Clamp01(t);
        float oneMinusT = 1f - t;

        return
            (3f * oneMinusT * oneMinusT * (vectors.p1 - vectors.p0) +
             6f * oneMinusT * t * (vectors.p2 - vectors.p1) +
             3f * t * t * (vectors.p3 - vectors.p2));
    }
 public void Reset()
 {
     vectors = new CurveVectors
               (
         new Vector3(1f, 0f, 0f),
         new Vector3(2f, 0f, 0f),
         new Vector3(3f, 0f, 0f),
         new Vector3(4f, 0f, 0f)
               );
 }
    public static Vector3 CalculatePoint(CurveVectors vectors, float t)
    {
        t = Mathf.Clamp01(t);
        float oneMinusT = 1f - t;

        //return cubic bezier formula
        return
            (oneMinusT * oneMinusT * oneMinusT * vectors.p0 +
             3f * oneMinusT * oneMinusT * t * vectors.p1 +
             3f * oneMinusT * t * t * vectors.p2 +
             t * t * t * vectors.p3);
    }