N个控制点的贝塞尔曲线

  //输入n个标志点,根据时间t(0 <= t <=1) 获取曲线上的坐标点 
    Vector3 CalculatePath(List points, float t) {
        Vector3 tempPos = Vector3.zero;
        for (int i = 0; i < points.Count; i++) {
            tempPos += GetYangNum(points.Count, i + 1) * points[i] * Mathf.Pow((1 - t), points.Count - (i + 1)) * Mathf.Pow(t, i);
        }
        return tempPos;
    }

    //获取杨辉三角的指定值
    int GetYangNum(int m, int n) {
        if (m == n || n == 1) {
            return 1;
        } else {
            return GetYangNum(m - 1, n - 1) + GetYangNum(m - 1, n);
        }
    }

你可能感兴趣的:(unity引擎)