예제 #1
0
        /*
         * Return the count of the number of horizontal sections of the
         * specified cubic Bezier curve.  Put the parameters for the
         * horizontal sections into the specified <code>ret</code> array.
         * <p>
         * If we examine the parametric equation in t, we have:
         *   Py(t) = C0(1-t)^3 + 3CP0 t(1-t)^2 + 3CP1 t^2(1-t) + C1 t^3
         *         = C0 - 3C0t + 3C0t^2 - C0t^3 +
         *           3CP0t - 6CP0t^2 + 3CP0t^3 +
         *           3CP1t^2 - 3CP1t^3 +
         *           C1t^3
         *   Py(t) = (C1 - 3CP1 + 3CP0 - C0) t^3 +
         *           (3C0 - 6CP0 + 3CP1) t^2 +
         *           (3CP0 - 3C0) t +
         *           (C0)
         * If we take the derivative, we get:
         *   Py(t) = Dt^3 + At^2 + Bt + C
         *   dPy(t) = 3Dt^2 + 2At + B = 0
         *        0 = 3*(C1 - 3*CP1 + 3*CP0 - C0)t^2
         *          + 2*(3*CP1 - 6*CP0 + 3*C0)t
         *          + (3*CP0 - 3*C0)
         *        0 = 3*(C1 - 3*CP1 + 3*CP0 - C0)t^2
         *          + 3*2*(CP1 - 2*CP0 + C0)t
         *          + 3*(CP0 - C0)
         *        0 = (C1 - CP1 - CP1 - CP1 + CP0 + CP0 + CP0 - C0)t^2
         *          + 2*(CP1 - CP0 - CP0 + C0)t
         *          + (CP0 - C0)
         *        0 = (C1 - CP1 + CP0 - CP1 + CP0 - CP1 + CP0 - C0)t^2
         *          + 2*(CP1 - CP0 - CP0 + C0)t
         *          + (CP0 - C0)
         *        0 = ((C1 - CP1) - (CP1 - CP0) - (CP1 - CP0) + (CP0 - C0))t^2
         *          + 2*((CP1 - CP0) - (CP0 - C0))t
         *          + (CP0 - C0)
         * that this method will return 0 if the equation is a line,
         * which is either always horizontal or never horizontal.
         * Completely horizontal curves need to be eliminated by other
         * means outside of this method.
         */
        public static int GetHorizontalParams(double c0, double cp0,
                                              double cp1, double c1,
                                              double[] ret)
        {
            if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1)
            {
                return(0);
            }
            c1    -= cp1;
            cp1   -= cp0;
            cp0   -= c0;
            ret[0] = cp0;
            ret[1] = (cp1 - cp0) * 2;
            ret[2] = (c1 - cp1 - cp1 + cp0);
            int numroots = QuadCurve.SolveQuadratic(ret, ret);
            int j        = 0;

            for (int i = 0; i < numroots; i++)
            {
                double t = ret[i];
                // No splits at t==0 and t==1
                if (t > 0 && t < 1)
                {
                    if (j < i)
                    {
                        ret[j] = t;
                    }
                    j++;
                }
            }
            return(j);
        }
예제 #2
0
        public override double NextVertical(double t0, double t1)
        {
            double[] eqn      = { _xcoeff1, 2 * _xcoeff2, 3 * _xcoeff3 };
            int      numroots = QuadCurve.SolveQuadratic(eqn, eqn);

            for (int i = 0; i < numroots; i++)
            {
                if (eqn[i] > t0 && eqn[i] < t1)
                {
                    t1 = eqn[i];
                }
            }
            return(t1);
        }
예제 #3
0
        public override void Enlarge(Rectangle r)
        {
            r.Add((int)(_x0 + .5),
                  (int)(_y0 + .5));
            double[] eqn      = { _xcoeff1, 2 * _xcoeff2, 3 * _xcoeff3 };
            int      numroots = QuadCurve.SolveQuadratic(eqn, eqn);

            for (int i = 0; i < numroots; i++)
            {
                double t = eqn[i];
                if (t > 0 && t < 1)
                {
                    r.Add((int)(XforT(t) + .5), (int)(YforT(t) + .5));
                }
            }
            r.Add((int)(_x1 + .5), (int)(_y1 + .5));
        }