//----------------------------------------------------------------------------
Real NaturalSpline3::GetVariationKey (int iKey, Real fT0, Real fT1,
    const Vector3& rkA, const Vector3& rkB) const
{
    Polynomial kXPoly(3);
    kXPoly[0] = m_akA[iKey].x;
    kXPoly[1] = m_akB[iKey].x;
    kXPoly[2] = m_akC[iKey].x;
    kXPoly[3] = m_akD[iKey].x;

    Polynomial kYPoly(3);
    kYPoly[0] = m_akA[iKey].y;
    kYPoly[1] = m_akB[iKey].y;
    kYPoly[2] = m_akC[iKey].y;
    kYPoly[3] = m_akD[iKey].y;

    Polynomial kZPoly(3);
    kZPoly[0] = m_akA[iKey].z;
    kZPoly[1] = m_akB[iKey].z;
    kZPoly[2] = m_akC[iKey].z;
    kZPoly[3] = m_akD[iKey].z;

    // construct line segment A + t*B
    Polynomial kLx(1), kLy(1), kLz(1);
    kLx[0] = rkA.x;
    kLx[1] = rkB.x;
    kLy[0] = rkA.y;
    kLy[1] = rkB.y;
    kLz[0] = rkA.z;
    kLz[1] = rkB.z;

    // compute |X(t) - L(t)|^2
    Polynomial kDx = kXPoly - kLx;
    Polynomial kDy = kYPoly - kLy;
    Polynomial kDz = kZPoly - kLz;
    Polynomial kNormSqr = kDx*kDx + kDy*kDy + kDz*kDz;

    // compute indefinite integral of |X(t)-L(t)|^2
    Polynomial kIntegral(kNormSqr.GetDegree()+1);
    kIntegral[0] = 0.0f;
    for (int i = 1; i <= kIntegral.GetDegree(); i++)
        kIntegral[i] = kNormSqr[i-1]/i;

    // compute definite Integral(t0,t1,|X(t)-L(t)|^2)
    Real fResult = kIntegral(fT1) - kIntegral(fT0);
    return fResult;
}
Beispiel #2
0
//----------------------------------------------------------------------------
Real PolynomialCurve3::GetVariation (Real fT0, Real fT1,
    const Vector3* pkP0, const Vector3* pkP1) const
{
    Vector3 kP0, kP1;
    if ( !pkP0 )
    {
        kP0 = GetPosition(fT0);
        pkP0 = &kP0;
    }
    if ( !pkP1 )
    {
        kP1 = GetPosition(fT1);
        pkP1 = &kP1;
    }

    // construct line segment A + t*B
    Real fInvDT = 1.0f/(fT1 - fT0);
    Vector3 kB = fInvDT*(*pkP1 - *pkP0);
    Vector3 kA = *pkP0 - fT0*kB;
    Polynomial kLx(1), kLy(1), kLz(1);
    kLx[0] = kA.x;
    kLx[1] = kB.x;
    kLy[0] = kA.y;
    kLy[1] = kB.y;
    kLz[0] = kA.z;
    kLz[1] = kB.z;

    // compute |X(t) - L(t)|^2
    Polynomial kDx = *m_pkXPoly - kLx;
    Polynomial kDy = *m_pkYPoly - kLy;
    Polynomial kDz = *m_pkZPoly - kLz;
    Polynomial kNormSqr = kDx*kDx + kDy*kDy + kDz*kDz;

    // compute indefinite integral of |X(t)-L(t)|^2
    Polynomial kIntegral(kNormSqr.GetDegree()+1);
    kIntegral[0] = 0.0f;
    for (int i = 1; i <= kIntegral.GetDegree(); i++)
        kIntegral[i] = kNormSqr[i-1]/i;

    // return definite Integral(t0,t1,|X(t)-L(t)|^2)
    Real fResult = kIntegral(fT1) - kIntegral(fT0);
    return fResult;
}