Package ru.dubov.primitives

Examples of ru.dubov.primitives.Point


    private static boolean isRightTurn(Point p0, Point p1, Point p2) {
        return (crossProduct(p0, p1, p2) < 0);
    }
   
    private static Point getLowestPoint(List<Point> points) {
        Point result = points.get(0);
       
        Point candidate;
        for (int i = 1; i < points.size(); i++) {
            candidate = points.get(i);
           
            if (candidate.getY() < result.getY() ||
                    candidate.getY() == result.getY() && candidate.getX() < result.getX()) {
                result = candidate;
            }
        }
       
        return result;
View Full Code Here


                    g.fillOval((int)p.getX() - 3,
                        (int)(getHeight() - p.getY() - 3), 5, 5);
                }

                if (state == 1) { // Рисуем оболочку
                    Point cur, next;
                    for(int i = 0; i < convexHull.size(); i++) {
                        cur = convexHull.get(i);
                        next = convexHull.get((i + 1) % convexHull.size());
                        g.drawLine((int)cur.getX(), (int)(getHeight() - cur.getY()),
                            (int)next.getX(), (int)(getHeight() - next.getY()));
                    }
                }
            }
        };
View Full Code Here

    }
   
    public void testConvexHull_Example() {
       
        ArrayList<Point> points = new ArrayList<Point>();
        points.add(new Point(1, 0));
        points.add(new Point(2, 7));
        points.add(new Point(20, 10)); // !!!
        points.add(new Point(10, 10)); // Граничный случай
        points.add(new Point(0, 10))// !!!
        points.add(new Point(1, 1));
        points.add(new Point(-5, 5));
       
        checkConvexHull(points);
    }
View Full Code Here

       
        for (int n = 3; n <= 20; n++) {
            ArrayList<Point> points = new ArrayList<Point>();
           
            for(int i = 0; i < n; i++) {
                points.add(new Point(rand.nextDouble()*100,
                                     rand.nextDouble()*100));
            }
       
            checkConvexHull(points);
        }
View Full Code Here

        jPanel1.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        if (state == 0) {
            Point pi = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
            points.add(pi);
        }
       
        jPanel1.repaint();
    }//GEN-LAST:event_jPanel1MousePressed
View Full Code Here

        ArrayList<Point> points = (ArrayList<Point>)pointsList.clone();
        Stack<Point> result = new Stack<Point>();
       
        // Получаем нижнюю левую точку - первую вершину оболочки - O(n)
       
        Point p0 = getLowestPoint(points);
        result.push(p0);
        points.remove(p0);
       
        // Оставшиеся вершины сортируем по возрастанию полярного угла - O(n*log(n))
       
        Collections.sort(points, new PointComparator(p0));
       
        // Перед началом сканирования заносим еще две точки в стек
       
        Iterator<Point> iter = points.iterator();
       
        Point p1 = iter.next();
        result.push(p1);
       
        Point p2 = iter.next();
        result.push(p2);
       
        // Совершаем проход по отсортированному списку,
        // определяя, какие вершины входят в оболочку - O(n)
       
        while (iter.hasNext()) {
            Point pi = iter.next();
            Point top = result.elementAt(result.size() - 1);
            Point nextToTop = result.elementAt(result.size() - 2);
           
            while (! isLeftTurn(nextToTop, top, pi)) {
                result.pop();
               
                // Не забываем обновить
View Full Code Here

        ArrayList<Point> points = (ArrayList<Point>)pointsList.clone();
        ArrayList<Point> result = new ArrayList<Point>();
       
        // Получаем нижнюю левую точку - первую вершину оболочки - O(n)
       
        Point p0 = getLowestPoint(points);
        result.add(p0);
        points.remove(p0);
       
        // Получаем последнюю вершину оболочки - O(n)
       
        Point pE = points.get(0);
        Point candidate;
        for(int i = 1; i < points.size(); i++) {
            candidate = points.get(i);
            if(crossProduct(p0, candidate, pE) < 0) {
                pE = candidate;
            }
        }
       
        // Строим цепь - O(h) шагов...
       
        Point next = null;
        Point last = p0;
        do {
            // ... на каждом - перебор O(n) точек, итого O(n*h) операций
            next = points.get(0);
           
            for(int i = 1; i < points.size(); i++) {
                candidate = points.get(i);
                if (crossProduct(last, candidate, next) > 0 ||
                        crossProduct(last, candidate, next) == 0 &&
                        last.dist(candidate) > last.dist(next)) {
                    next = candidate;
                }
            }
           
            result.add(next);
View Full Code Here

    private static boolean isLeftTurn(Point p0, Point p1, Point p2) {
        return (crossProduct(p0, p1, p2) > 0);
    }
   
    private static Point getLowestPoint(ArrayList<Point> points) {
        Point result = points.get(0);
       
        Point candidate;
        for (int i = 1; i < points.size(); i++) {
            candidate = points.get(i);
           
            if (candidate.getY() < result.getY() ||
                    candidate.getY() == result.getY() && candidate.getX() < result.getX()) {
                result = candidate;
            }
        }
       
        return result;
View Full Code Here

     * @param s2 The second segment
     * @return true, if the segments intersect, false otherwise
     */
    public static boolean two(Segment s1, Segment s2) {
       
        Point p1 = s1.getLeft();
        Point p2 = s1.getRight();
        Point p3 = s2.getLeft();
        Point p4 = s2.getRight();
       
        double d1 = direction(p3, p4, p1);
        double d2 = direction(p3, p4, p2);
        double d3 = direction(p1, p2, p3);
        double d4 = direction(p1, p2, p4);
View Full Code Here

        jPanel1.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        if (state == 0) {
            pStart = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
            state = 1;
        } else if (state == 1) {
            pEnd = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
           
            segments.add(new Segment(pStart, pEnd));
            state = 0;
        }
       
View Full Code Here

TOP

Related Classes of ru.dubov.primitives.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.