Example #1
0
        /// <summary>
        /// 指定の位置の座標を取得。
        /// </summary>
        protected virtual Vector3 CalcuratePoint(float t)
        {
            Vector3 linePoint = Vector3.zero;

            for (int i = 0; i < this.points.Length; ++i)
            {
                float bs = BSplineCurve.BSplineBasisFunc(i, this.degree, t, this.knots);
                linePoint += bs * this.points[i];
            }

            return(linePoint);
        }
Example #2
0
        /// <summary>
        /// 重みも考慮し、指定の位置の座標を取得。
        /// </summary>
        protected override Vector3 CalcuratePoint(float t)
        {
            Vector3 linePoint = Vector3.zero;
            float   weight    = 0f;

            for (int i = 0; i < this.points.Length; ++i)
            {
                float bs = BSplineCurve.BSplineBasisFunc(i, this.degree, t, this.knots);
                linePoint += bs * this.weights[i] * this.points[i];
                weight    += bs * this.weights[i];
            }

            return(linePoint / weight);
        }
Example #3
0
        /// <summary>
        /// Bスプライン基底関数。
        /// </summary>
        protected static float BSplineBasisFunc(int i, int degree, float t, float[] knots)
        {
            if (degree == 0)
            {
                if (t >= knots[i] && t < knots[i + 1])
                {
                    return(1f);
                }
                else
                {
                    return(0f);
                }
            }

            float w1           = 0f;
            float w2           = 0f;
            float denominatorA = knots[i + degree] - knots[i];
            float denominatorB = knots[i + degree + 1] - knots[i + 1];

            if (denominatorA != 0f)
            {
                w1 = (t - knots[i]) / denominatorA;
            }

            if (denominatorB != 0f)
            {
                w2 = (knots[i + degree + 1] - t) / denominatorB;
            }


            float firstTerm  = 0f;
            float secondTerm = 0f;

            if (w1 != 0f)
            {
                firstTerm = w1 * BSplineCurve.BSplineBasisFunc(i, degree - 1, t, knots);
            }

            if (w2 != 0f)
            {
                secondTerm = w2 * BSplineCurve.BSplineBasisFunc(i + 1, degree - 1, t, knots);
            }

            return(firstTerm + secondTerm);
        }