Пример #1
0
        /**
         * Returns how many times ray from point (x,y) cross quard curve
         */
        public static int crossQuad(double x1, double y1, double cx, double cy, double x2, double y2, double x, double y)
        {
            // LEFT/RIGHT/UP/EMPTY
            if ((x < x1 && x < cx && x < x2) ||
                (x > x1 && x > cx && x > x2) ||
                (y > y1 && y > cy && y > y2) ||
                (x1 == cx && cx == x2))
            {
                return(0);
            }

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

            // INSIDE
            QuadCurve c  = new QuadCurve(x1, y1, cx, cy, 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 rectangle stripe cross quad curve or the are intersect
         */
        public static int intersectQuad(double x1, double y1, double cx, double cy, double x2, double y2, double rx1, double ry1, double rx2, double ry2)
        {
            // LEFT/RIGHT/UP ------------------------------------------------------
            if ((rx2 < x1 && rx2 < cx && rx2 < x2) ||
                (rx1 > x1 && rx1 > cx && rx1 > x2) ||
                (ry1 > y1 && ry1 > cy && ry1 > y2))
            {
                return 0;
            }

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

            // INSIDE -------------------------------------------------------------
            QuadCurve c = new QuadCurve(x1, y1, cx, cy, 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);

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

            // Build bound --------------------------------------------------------
            double minX = px1 - DELTA;
            double maxX = px2 + DELTA;
            double[] bound = new double[28];
            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 extremal points`
            rc2 = c.solveExtrem(res2);
            bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
            // Add start and end
            if (rx1 < x1 && x1 < rx2)
            {
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 4;
            }
            if (rx1 < x2 && x2 < rx2)
            {
                bound[bc++] = 1.0;
                bound[bc++] = c.ax;
                bound[bc++] = c.ay;
                bound[bc++] = 5;
            }
            // End build bound ----------------------------------------------------

            int cross = crossBound(bound, bc, py1, py2);
            if (cross != UNKNOWN)
            {
                return cross;
            }
            return c.cross(res1, rc1, py1, py2);
        }
Пример #3
0
        /**
         * Returns how many times ray from point (x,y) cross quard curve
         */
        public static int crossQuad(double x1, double y1, double cx, double cy, double x2, double y2, double x, double y)
        {
            // LEFT/RIGHT/UP/EMPTY
            if ((x < x1 && x < cx && x < x2) ||
                (x > x1 && x > cx && x > x2) ||
                (y > y1 && y > cy && y > y2) ||
                (x1 == cx && cx == x2))
            {
                return 0;
            }

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

            // INSIDE
            QuadCurve c = new QuadCurve(x1, y1, cx, cy, 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);
        }
Пример #4
0
        /**
         * Returns how many times rectangle stripe cross quad curve or the are intersect
         */
        public static int intersectQuad(double x1, double y1, double cx, double cy, double x2, double y2, double rx1, double ry1, double rx2, double ry2)
        {
            // LEFT/RIGHT/UP ------------------------------------------------------
            if ((rx2 < x1 && rx2 < cx && rx2 < x2) ||
                (rx1 > x1 && rx1 > cx && rx1 > x2) ||
                (ry1 > y1 && ry1 > cy && ry1 > y2))
            {
                return(0);
            }

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

            // INSIDE -------------------------------------------------------------
            QuadCurve c   = new QuadCurve(x1, y1, cx, cy, 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);

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

            // Build bound --------------------------------------------------------
            double minX = px1 - DELTA;
            double maxX = px2 + DELTA;

            double[] bound = new double[28];
            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 extremal points`
            rc2 = c.solveExtrem(res2);
            bc  = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
            // Add start and end
            if (rx1 < x1 && x1 < rx2)
            {
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 0.0;
                bound[bc++] = 4;
            }
            if (rx1 < x2 && x2 < rx2)
            {
                bound[bc++] = 1.0;
                bound[bc++] = c.ax;
                bound[bc++] = c.ay;
                bound[bc++] = 5;
            }
            // End build bound ----------------------------------------------------

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

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