/// <summary> /// Finds the point on this spline that minimises a given distance function /// </summary> /// <param name="distance"> Distance function </param> /// <param name="iterations"> Number of iterations (accuracy). 5 is pretty good. </param> /// <returns> Returns the time on the spline of the closest point </returns> public override float FindClosestPoint( DistanceToPointDelegate distance, int iterations ) { CatmullRomSpline.DistanceCalculator calculator = new CatmullRomSpline.DistanceCalculator( distance ); float closestFraction = 0; int numControlPoints = m_BaseSpline.ControlPoints.Count; CatmullRomSpline.Evaluator eval = new CatmullRomSpline.Evaluator( ); for ( int cpIndex = 0; cpIndex < numControlPoints; ++cpIndex ) { MakeEvaluator( ref eval, cpIndex, m_BaseSpline, m_Offset ); closestFraction = calculator.GetClosestPointInInterval( eval, 1.0f, iterations ); } return closestFraction; }
/// <summary> /// Calculates the position on the spline at fraction t /// </summary> public override Point3 EvaluatePosition( float t ) { CatmullRomSpline.Evaluator eval = new CatmullRomSpline.Evaluator( ); MakeEvaluator( ref eval, t, m_BaseSpline, m_Offset ); return eval.EvaluatePosition( ); }
/// <summary> /// Calculates the second derivative on the spline at fraction t /// </summary> public override Vector3 EvaluateSecondDerivative( float t ) { CatmullRomSpline.Evaluator eval = new CatmullRomSpline.Evaluator( ); MakeEvaluator( ref eval, t, m_BaseSpline, m_Offset ); return eval.EvaluateSecondDerivative( ); }
/// <summary> /// Calculates the tangent, bi-normal, normal, speed and curvature on the spline at fraction t /// </summary> public override CurveFrame EvaluateFrame( float t ) { CatmullRomSpline.Evaluator eval = new CatmullRomSpline.Evaluator( ); MakeEvaluator( ref eval, t, m_BaseSpline, m_Offset ); return eval.EvaluateFrame( ); }