示例#1
0
        /**
         * Returns how many times ray from point (x,y) cross cubic curve
         */
        public static int crossCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double x, double y)
        {
            // LEFT/RIGHT/UP/EMPTY
            if ((x < x1 && x < cx1 && x < cx2 && x < x2) ||
                (x > x1 && x > cx1 && x > cx2 && x > x2) ||
                (y > y1 && y > cy1 && y > cy2 && y > y2) ||
                (x1 == cx1 && cx1 == cx2 && cx2 == x2))
            {
                return 0;
            }

            // DOWN
            if (y < y1 && y < cy1 && y < cy2 && y < y2 && x != x1 && x != x2)
            {
                if (x1 < x2)
                {
                    return x1 < x && x < x2 ? 1 : 0;
                }
                return x2 < x && x < x1 ? -1 : 0;
            }

            // INSIDE
            CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
            double px = x - x1;
            double py = y - y1;
            double[] res = new double[3];
            int rc = c.solvePoint(res, px);
            return c.cross(res, rc, py, py);
        }
示例#2
0
        /**
         * Returns how many times ray from point (x,y) cross cubic curve
         */
        public static int crossCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double x, double y)
        {
            // LEFT/RIGHT/UP/EMPTY
            if ((x < x1 && x < cx1 && x < cx2 && x < x2) ||
                (x > x1 && x > cx1 && x > cx2 && x > x2) ||
                (y > y1 && y > cy1 && y > cy2 && y > y2) ||
                (x1 == cx1 && cx1 == cx2 && cx2 == x2))
            {
                return(0);
            }

            // DOWN
            if (y < y1 && y < cy1 && y < cy2 && y < y2 && x != x1 && x != x2)
            {
                if (x1 < x2)
                {
                    return(x1 < x && x < x2 ? 1 : 0);
                }
                return(x2 < x && x < x1 ? -1 : 0);
            }

            // INSIDE
            CubicCurve c  = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
            double     px = x - x1;
            double     py = y - y1;

            double[] res = new double[3];
            int      rc  = c.solvePoint(res, px);

            return(c.cross(res, rc, py, py));
        }
示例#3
0
        /**
         * Returns how many times rectangle stripe cross cubic curve or the are intersect
         */
        public static int intersectCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double rx1, double ry1, double rx2, double ry2)
        {
            // LEFT/RIGHT/UP
            if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) ||
                (rx1 > x1 && rx1 > cx1 && rx1 > cx2 && rx1 > x2) ||
                (ry1 > y1 && ry1 > cy1 && ry1 > cy2 && ry1 > y2))
            {
                return 0;
            }

            // DOWN
            if (ry2 < y1 && ry2 < cy1 && ry2 < cy2 && ry2 < y2 && rx1 != x1 && rx1 != x2)
            {
                if (x1 < x2)
                {
                    return x1 < rx1 && rx1 < x2 ? 1 : 0;
                }
                return x2 < rx1 && rx1 < x1 ? -1 : 0;
            }

            // INSIDE
            CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
            double px1 = rx1 - x1;
            double py1 = ry1 - y1;
            double px2 = rx2 - x1;
            double py2 = ry2 - y1;

            double[] res1 = new double[3];
            double[] res2 = new double[3];
            int rc1 = c.solvePoint(res1, px1);
            int rc2 = c.solvePoint(res2, px2);

            // LEFT/RIGHT
            if (rc1 == 0 && rc2 == 0)
            {
                return 0;
            }

            double minX = px1 - DELTA;
            double maxX = px2 + DELTA;

            // Build bound --------------------------------------------------------
            double[] bound = new double[40];
            int bc = 0;
            // Add roots
            bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
            bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
            // Add extrimal points
            rc2 = c.solveExtremX(res2);
            bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
            rc2 = c.solveExtremY(res2);
            bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 4);
            // Add start and end
            if (rx1 < x1 && x1 < rx2)
            {
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 6;
            }
            if (rx1 < x2 && x2 < rx2)
            {
                bound[bc++] = 1.0;
                bound[bc++] = c.ax;
                bound[bc++] = c.ay;
                bound[bc++] = 7;
            }
            // End build bound ----------------------------------------------------

            int cross = crossBound(bound, bc, py1, py2);
            if (cross != UNKNOWN)
            {
                return cross;
            }
            return c.cross(res1, rc1, py1, py2);
        }
示例#4
0
        /**
         * Returns how many times rectangle stripe cross cubic curve or the are intersect
         */
        public static int intersectCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double rx1, double ry1, double rx2, double ry2)
        {
            // LEFT/RIGHT/UP
            if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) ||
                (rx1 > x1 && rx1 > cx1 && rx1 > cx2 && rx1 > x2) ||
                (ry1 > y1 && ry1 > cy1 && ry1 > cy2 && ry1 > y2))
            {
                return(0);
            }

            // DOWN
            if (ry2 < y1 && ry2 < cy1 && ry2 < cy2 && ry2 < y2 && rx1 != x1 && rx1 != x2)
            {
                if (x1 < x2)
                {
                    return(x1 < rx1 && rx1 < x2 ? 1 : 0);
                }
                return(x2 < rx1 && rx1 < x1 ? -1 : 0);
            }

            // INSIDE
            CubicCurve c   = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
            double     px1 = rx1 - x1;
            double     py1 = ry1 - y1;
            double     px2 = rx2 - x1;
            double     py2 = ry2 - y1;

            double[] res1 = new double[3];
            double[] res2 = new double[3];
            int      rc1  = c.solvePoint(res1, px1);
            int      rc2  = c.solvePoint(res2, px2);

            // LEFT/RIGHT
            if (rc1 == 0 && rc2 == 0)
            {
                return(0);
            }

            double minX = px1 - DELTA;
            double maxX = px2 + DELTA;

            // Build bound --------------------------------------------------------
            double[] bound = new double[40];
            int      bc    = 0;

            // Add roots
            bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
            bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
            // Add extrimal points
            rc2 = c.solveExtremX(res2);
            bc  = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
            rc2 = c.solveExtremY(res2);
            bc  = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 4);
            // Add start and end
            if (rx1 < x1 && x1 < rx2)
            {
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 6;
            }
            if (rx1 < x2 && x2 < rx2)
            {
                bound[bc++] = 1.0;
                bound[bc++] = c.ax;
                bound[bc++] = c.ay;
                bound[bc++] = 7;
            }
            // End build bound ----------------------------------------------------

            int cross = crossBound(bound, bc, py1, py2);

            if (cross != UNKNOWN)
            {
                return(cross);
            }
            return(c.cross(res1, rc1, py1, py2));
        }