本文整理汇总了C#中ICurve.Derivative方法的典型用法代码示例。如果您正苦于以下问题:C# ICurve.Derivative方法的具体用法?C# ICurve.Derivative怎么用?C# ICurve.Derivative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICurve
的用法示例。
在下文中一共展示了ICurve.Derivative方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: CreateParallelogramOnSubSeg
/// <summary>
/// Creates a bounding parallelogram on a curve segment
/// We suppose here that the segment is convex or concave from start to end,
/// that is the region bounded by the straight segment seg[start], seg[end] and the curve seg is convex
/// </summary>
internal static bool CreateParallelogramOnSubSeg(double start, double end, ICurve seg, ref Parallelogram box,
Point startPoint, Point endPoint) {
if (seg is CubicBezierSegment)
return CreateParallelogramOnSubSegOnBezierSeg(start, end, seg, ref box);
Point tan1 = seg.Derivative(start);
Point tan2 = seg.Derivative(end);
Point tan2Perp = Point.P(-tan2.Y, tan2.X);
Point p = endPoint - startPoint;
double numerator = p * tan2Perp;
double denumerator = (tan1 * tan2Perp);
double x;// = (p * tan2Perp) / (tan1 * tan2Perp);
if (Math.Abs(numerator) < ApproximateComparer.DistanceEpsilon)
x = 0;
else if (Math.Abs(denumerator) < ApproximateComparer.DistanceEpsilon) {
//it is degenerated; adjacent sides are parallel, but
//since p * tan2Perp is big it does not contain e
return false;
} else x = numerator / denumerator;
tan1 *= x;
box = new Parallelogram(startPoint, tan1, endPoint - startPoint - tan1);
#if DEBUGCURVES
if (!box.Contains(seg[end]))
{
throw new InvalidOperationException();//"the box does not contain the end of the segment");
}
#endif
double delta = (end - start) / 64;
for (int i = 1; i < 64; i++) {
if (!box.Contains(seg[start + delta * i]))
return false;
}
return true;
}
示例3: CurvesAreCloseAtParams
static bool CurvesAreCloseAtParams(ICurve c0, ICurve c1, double c0S, double c1S) {
return Close(c0[c0S], c1[c1S]) && Close(c0.Derivative(c0S), c1.Derivative(c1S));
}
示例4: TangentOnICurve
static CurveTangent TangentOnICurve(double p, ICurve iCurve) {
return new CurveTangent(iCurve[p], iCurve.Derivative(p));
}