Example #1
0
        public static (double X, double Y) BezierQuintic(double t, double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, double eX, double eY, double fX, double fY)
        {
            var abcde = InterpolateBezierQuartic2DTests.QuarticBezierInterpolate2D(t, aX, aY, bX, bY, cX, cY, dX, dY, eX, eY);
            var bcdef = InterpolateBezierQuartic2DTests.QuarticBezierInterpolate2D(t, bX, bY, cX, cY, dX, dY, eX, eY, fX, fY);

            return(InterpolateLinear2DTests.LinearInterpolate2D(t, abcde.X, abcde.Y, bcdef.X, bcdef.Y));
        }
Example #2
0
        public static (Point2D, double) FindNearestPoint(double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, double eX, double eY, double x, double y)
        {
            var(a, b, c, d, e, f, g, h) = GetSepticPolynomialFromQuarticBezierAndPointTests.GetSepticPolynomialFromQuarticBezierAndPoint(aX, aY, bX, bY, cX, cY, dX, dY, eX, eY, x, y);
            var candidates = FindAllRealRootsInIntervalTests.FindAllRootsInInterval(0d, 1d, a, b, c, d, e, f, g, h);

            // Find the candidate that yields the closest point on the bezier to the given point.
            var t           = double.NaN;
            var output      = (double.NaN, double.NaN);
            var minDistance = double.MaxValue;

            foreach (var candidate in candidates)
            {
                var ptAtCandidate = InterpolateBezierQuartic2DTests.QuarticBezierInterpolate2D(candidate, aX, aY, bX, bY, cX, cY, dX, dY, eX, eY);
                var distance      = SquareDistanceTests.SquareDistance(ptAtCandidate.X, ptAtCandidate.Y, x, y);
                if (distance < minDistance)
                {
                    minDistance = distance;
                    t           = candidate;
                    output      = ptAtCandidate;
                }
            }

            return(output, t);
        }