void CubicPolynomialCurve3<Real>::Tessellate ( int level ) { // Vertices V = (2^L+1). int twoPowL = ( 1 << level ); mNumVertices = twoPowL + 1; delete1( mVertices ); mVertices = new1<Vector3<Real> >( mNumVertices ); // Indices of endpoints, I[t]. IntervalParameters IP; IP.I0 = 0; IP.I1 = twoPowL; // Vertices for subdivision. Vector3<Real>* X = mVertices; X[IP.I0] = GetPosition( mTMin ); X[IP.I1] = GetPosition( mTMax ); // Recursive subdivision. if ( level > 0 ) { IP.Xuu[0] = GetSecondDerivative( mTMin ); IP.Xuu[1] = GetSecondDerivative( mTMax ); Subdivide( --level, ( Real )0.25, X, IP ); } }
Vector3<Real> Curve3<Real>::GetNormal ( Real t ) const { Vector3<Real> velocity = GetFirstDerivative( t ); Vector3<Real> acceleration = GetSecondDerivative( t ); Real VDotV = velocity.Dot( velocity ); Real VDotA = velocity.Dot( acceleration ); Vector3<Real> normal = VDotV * acceleration - VDotA * velocity; normal.Normalize(); return normal; }
Vector3 Curve<Real>::GetNormal (Real t) { Vector3 velocity = GetFirstDerivative(t); Vector3 acceleration = GetSecondDerivative(t); Real VDotV = dot(velocity,velocity); Real VDotA = dot(velocity,acceleration); Vector3 normal = VDotV*acceleration - VDotA*velocity; normal.normalize(); return normal; }
void Curve3<Real>::GetFrame ( Real t, Vector3<Real>& position, Vector3<Real>& tangent, Vector3<Real>& normal, Vector3<Real>& binormal ) const { position = GetPosition( t ); Vector3<Real> velocity = GetFirstDerivative( t ); Vector3<Real> acceleration = GetSecondDerivative( t ); Real VDotV = velocity.Dot( velocity ); Real VDotA = velocity.Dot( acceleration ); normal = VDotV * acceleration - VDotA * velocity; normal.Normalize(); tangent = velocity; tangent.Normalize(); binormal = tangent.Cross( normal ); }
void Curve<Real>::GetFrame (Real t, Vector3& position, Vector3& tangent, Vector3& normal, Vector3& binormal) { position = GetPosition(t); Vector3 velocity = GetFirstDerivative(t); Vector3 acceleration = GetSecondDerivative(t); Real VDotV = dot(velocity,velocity); Real VDotA = dot(velocity,acceleration); normal = VDotV*acceleration - VDotA*velocity; normal.normalize(); tangent = velocity; tangent.normalize(); binormal = tangent.cross(normal); }
Real Curve3<Real>::GetTorsion ( Real t ) const { Vector3<Real> velocity = GetFirstDerivative( t ); Vector3<Real> acceleration = GetSecondDerivative( t ); Vector3<Real> cross = velocity.Cross( acceleration ); Real denom = cross.SquaredLength(); if ( denom >= Math<Real>::ZERO_TOLERANCE ) { Vector3<Real> jerk = GetThirdDerivative( t ); Real numer = cross.Dot( jerk ); return numer / denom; } else { // Torsion is indeterminate, just return 0. return ( Real )0; } }
Real Curve3<Real>::GetCurvature ( Real t ) const { Vector3<Real> velocity = GetFirstDerivative( t ); Real speedSqr = velocity.SquaredLength(); if ( speedSqr >= Math<Real>::ZERO_TOLERANCE ) { Vector3<Real> acceleration = GetSecondDerivative( t ); Vector3<Real> cross = velocity.Cross( acceleration ); Real numer = cross.Length(); Real denom = Math<Real>::Pow( speedSqr, ( Real )1.5 ); return numer / denom; } else { // Curvature is indeterminate, just return 0. return ( Real )0; } }
Real Curve<Real>::GetTorsion (Real t) { Vector3 velocity = GetFirstDerivative(t); Vector3 acceleration = GetSecondDerivative(t); Vector3 _cross = velocity.cross(acceleration); Real denom = _cross.squaredNorm(); if (denom >= REAL_ZERO_TOLERANCE) { Vector3 jerk = GetThirdDerivative(t); Real numer = dot(_cross,jerk); return numer/denom; } else { // Torsion is indeterminate, just return 0. return (Real)0; } }
Real Curve<Real>::GetCurvature (Real t) { Vector3 velocity = GetFirstDerivative(t); Real speedSqr = velocity.squaredNorm(); if (speedSqr >= REAL_ZERO_TOLERANCE) { Vector3 acceleration = GetSecondDerivative(t); Vector3 _cross = velocity.cross(acceleration); Real numer = _cross.norm(); Real denom = pow(speedSqr, (Real)1.5); return numer/denom; } else { // Curvature is indeterminate, just return 0. return (Real)0; } }