示例#1
0
  public Point2D getClosestIntersectionToStart(Shape withThisShape) {
    // first, get the sides of the shape
    List<LineSegment> shapeSides = Utilities.getSides(withThisShape);

    // go through all the sides, and see if there are any intersections
    // there may be more than 1
    List<Point2D> shapeIntersectionPoints = new ArrayList<Point2D>();

    for (Line2D curSide : shapeSides) {
      if (curSide.intersectsLine(this)) {
        Point2D intersectionPoint = Utilities.getIntersectionPoint(this, curSide);
        shapeIntersectionPoints.add(intersectionPoint);
      }
    }

    if (shapeIntersectionPoints.size() <= 0) {
      return null;
    } else if (shapeIntersectionPoints.size() == 1) {
      return shapeIntersectionPoints.get(0);
    } else {
      // get the point closest to P1
      Point2D closestIntersectionPoint = null;
      double closestIntersectionPointDistSq = java.lang.Double.MAX_VALUE;
      for (Point2D curPoint : shapeIntersectionPoints) {
        double curDistSq = curPoint.distanceSq(this.getP1());
        if (curDistSq < closestIntersectionPointDistSq) {
          closestIntersectionPointDistSq = curDistSq;
          closestIntersectionPoint = curPoint;
        }
      }
      return closestIntersectionPoint;
    }
  }
示例#2
0
 public LinkedList<LineWorldObject> getLineWorldObjectsOnLine(Line2D line, double radius) {
   LinkedList<LineWorldObject> objectsInSelection = new LinkedList<LineWorldObject>();
   for (LineWorldObject o : lineObjects) {
     if (o.getXInCM() == o.getX2InCM()) {
       if (line.intersectsLine(
           o.getXInCM(), o.getYInCM() - radius, o.getX2InCM(), o.getY2InCM() + radius)) {
         objectsInSelection.add(o);
       }
     } else {
       if (line.intersectsLine(
           o.getXInCM() - radius, o.getYInCM(), o.getX2InCM() + radius, o.getY2InCM())) {
         objectsInSelection.add(o);
       }
     }
   }
   return objectsInSelection;
 }
示例#3
0
  public void test(TestHarness harness) {
    Line2D line1 = new Line2D.Double(0.0, 0.0, 1.0, 0.0);
    harness.check(line1.intersectsLine(0.0, 0.0, 1.0, 0.0));
    harness.check(line1.intersectsLine(0.0, 0.0, 1.0, 1.0));
    harness.check(line1.intersectsLine(1.0, 1.0, 1.0, 0.0));
    harness.check(line1.intersectsLine(0.5, 0.5, 0.5, -0.5));
    harness.check(!line1.intersectsLine(0.0, 1.0, 1.0, 1.0));

    harness.check(line1.intersectsLine(new Line2D.Double(0.0, 0.0, 1.0, 0.0)));
    harness.check(line1.intersectsLine(new Line2D.Double(0.0, 0.0, 1.0, 1.0)));
    harness.check(line1.intersectsLine(new Line2D.Double(1.0, 1.0, 1.0, 0.0)));
    harness.check(line1.intersectsLine(new Line2D.Double(0.5, 0.5, 0.5, -0.5)));
    harness.check(!line1.intersectsLine(new Line2D.Double(0.0, 1.0, 1.0, 1.0)));

    boolean pass = false;
    try {
      line1.intersectsLine(null);
    } catch (NullPointerException e) {
      pass = true;
    }
    harness.check(pass);
  }
  /**
   * Compares all edges of two regions to see if any of them intersect.
   *
   * @param region the region to check
   * @return whether any edges of a region intersect
   */
  protected boolean intersectsEdges(ProtectedRegion region) {
    List<BlockVector2D> pts1 = getPoints();
    List<BlockVector2D> pts2 = region.getPoints();
    BlockVector2D lastPt1 = pts1.get(pts1.size() - 1);
    BlockVector2D lastPt2 = pts2.get(pts2.size() - 1);
    for (BlockVector2D aPts1 : pts1) {
      for (BlockVector2D aPts2 : pts2) {

        Line2D line1 =
            new Line2D.Double(
                lastPt1.getBlockX(), lastPt1.getBlockZ(), aPts1.getBlockX(), aPts1.getBlockZ());

        if (line1.intersectsLine(
            lastPt2.getBlockX(), lastPt2.getBlockZ(), aPts2.getBlockX(), aPts2.getBlockZ())) {
          return true;
        }
        lastPt2 = aPts2;
      }
      lastPt1 = aPts1;
    }
    return false;
  }
示例#5
0
文件: Line.java 项目: DusonWang/rtree
 public boolean intersects(Line b) {
   Line2D line1 = new Line2D.Float(x1, y1, x2, y2);
   Line2D line2 = new Line2D.Float(b.x1(), b.y1(), b.x2(), b.y2());
   return line2.intersectsLine(line1);
 }
示例#6
0
文件: World.java 项目: munro/lzr
 public static boolean intersectsLine(Vector2f a, Vector2f b, Vector2f c, Vector2f d) {
   Line2D l1 = new Line2D.Float(a.x, a.y, b.x, b.y);
   Line2D l2 = new Line2D.Float(c.x, c.y, d.x, d.y);
   return l1.intersectsLine(l2);
 }