本文整理汇总了C#中ICurve.SecondDerivative方法的典型用法代码示例。如果您正苦于以下问题:C# ICurve.SecondDerivative方法的具体用法?C# ICurve.SecondDerivative怎么用?C# ICurve.SecondDerivative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICurve
的用法示例。
在下文中一共展示了ICurve.SecondDerivative方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClosestPoint
///// <summary>
///// Gets the closest point on the curve to the point
///// </summary>
///// <param name="curve"></param>
///// <param name="coeff"></param>
///// <param name="hint">will return Double.MaxVal if Newton iterations fail</param>
///// <param name="closestPointParam"></param>
internal static double ClosestPoint(ICurve curve, Point a, double hint, double low, double high) {
/*
* Let F=(c(t)-a)^2. We try to bring to zero the first derivative of F, Ft. Denote it by f(t).
* Applying the Newton method we see that dt=-f(t)/der(f(t)
* The first derivative of F, f, has the form (c-a)*ct. We discarded a multiplier here.
* The second derivative has the form ct*ct+(c-a)*ctt
* The new t becomes t-dt
*/
const int numberOfIterationsMax = 5;
const int numberOfOverShootsMax = 5;
double t = hint;
int numberOfIteration = 0;
int numberOfOvershoots = 0;
double dt;
bool abort = false;
do {
Point c = curve[t];
Point ct = curve.Derivative(t);
Point ctt = curve.SecondDerivative(t);
double secondDerivative = ct * ct + (c - a) * ctt;
if (Math.Abs(secondDerivative) < ApproximateComparer.Tolerance)
return t;
dt = (c - a) * ct / secondDerivative;
t -= dt;
if (t > high + ApproximateComparer.Tolerance) {
t = high;
numberOfOvershoots++;
} else if (t < low - ApproximateComparer.Tolerance) {
t = low;
numberOfOvershoots++;
}
numberOfIteration++;
} while (Math.Abs(dt) > ApproximateComparer.Tolerance &&!
(abort = (numberOfIteration >= numberOfIterationsMax || numberOfOvershoots >= numberOfOverShootsMax)));
//may be the initial value was just fine
if (abort && (curve[hint] - a).Length < ApproximateComparer.DistanceEpsilon)
t = hint;
return t;
}