Refine search
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { // Log.println("rect x=" + rect.getX() + " y=" + rect.getY() + " w=" + rect.getWidth() + " h=" // + rect.getHeight()); // Log.println("tangeante (" + tangeante.getX1() + "," + tangeante.getY1() + ") (" + tangeante.getX2() // + "," + tangeante.getY2() + ")"); final DotPath result = new DotPath(); // final Point2D inter = BezierUtils.intersect((Line2D.Double) // tangeante, rect); Point2D inter = new LineRectIntersection(tangeante, rect).getIntersection(); // Log.println("inter=" + inter); if (inter == null) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); inter = LineRectIntersection.getCloser(tangeante.getP1(), p1, p2, p3, p4); } final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante.getX1(), tangeante.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }
/** * Check whether the abscissae of the provided line embrace * the provided abscissa value (assuming line points are defined * in increasing abscissa order). * * @param line the provided line * @param x the abscissa value * @return true if x is within line abscissae */ public static boolean xEmbraces (Line2D line, double x) { return (x >= line.getX1()) && (x <= line.getX2()); }
/** * This method calculates intersections of two lines. * @param a Line 1 * @param b Line 2 * @return Intersection point */ private static Point getLinesIntersection(Line2D a, Line2D b) { double d = (a.getX1() - a.getX2()) * (b.getY2() - b.getY1()) - (a.getY1() - a.getY2()) * (b.getX2() - b.getX1()); double da = (a.getX1() - b.getX1()) * (b.getY2() - b.getY1()) - (a.getY1() - b.getY1()) * (b.getX2() - b.getX1()); double ta = da / d; Point p = new Point(); p.setLocation(a.getX1() + ta * (a.getX2() - a.getX1()), a.getY1() + ta * (a.getY2() - a.getY1())); return p; } }
/** * Compute the structure width, based on borders points only. * * @return a better width */ public double getWidth () { double xLeft = Double.MAX_VALUE; double xRight = Double.MIN_VALUE; for (BeamLine line : lines) { xLeft = Math.min(xLeft, line.median.getX1()); xRight = Math.max(xRight, line.median.getX2()); } return xRight - xLeft + 1; }
private SortedMap<Double, Line2D> getLinesMap (double globalSlope, List<BasicLine> topLines) { SortedMap<Double, Line2D> map = new TreeMap<>(); // Use refined value of global slope and flag each line WRT reference line for (BasicLine l : topLines) { Line2D line = l.toDouble(); double x = (line.getX1() + line.getX2()) / 2; double y = l.yAtX(x); double dy = y - LineUtil.yAtX(center, globalSlope, x); map.put(dy, line); } return map; }
public TwoLinesIntersection(Line2D lineA, Line2D lineB) { final double x1 = lineA.getX1(); final double y1 = lineA.getY1(); final double x2 = lineA.getX2(); final double y2 = lineA.getY2(); final double x3 = lineB.getX1(); final double y3 = lineB.getY1(); final double x4 = lineB.getX2(); final double y4 = lineB.getY2(); final double den = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); final double uA1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3); final double uA = uA1 / den; // final double uB1 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3); // uB = uB1 / den; final double x = x1 + uA * (x2 - x1); final double y = y1 + uA * (y2 - y1); inter = new Point2D.Double(x, y); }
public LineSegmentIntersection(Line2D segment, Line2D lineB) { final double x1 = segment.getX1(); final double y1 = segment.getY1(); final double x2 = segment.getX2(); final double y2 = segment.getY2(); final double x3 = lineB.getX1(); final double y3 = lineB.getY1(); final double x4 = lineB.getX2(); final double y4 = lineB.getY2(); final double den = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); if (den == 0) { inter = null; } else { final double uA1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3); final double uA = uA1 / den; final double x = x1 + uA * (x2 - x1); final double y = y1 + uA * (y2 - y1); if (uA >= 0 && uA <= 1) { inter = new Point2D.Double(x, y); } else { inter = null; } } }
private static boolean collisionCheck(MinMax rect, Line2D hline) { if (hline.getY1() != hline.getY2()) { throw new IllegalArgumentException(); } if (hline.getY1() < rect.getMinY()) { return false; } if (hline.getY1() > rect.getMaxY()) { return false; } final double x1 = Math.min(hline.getX1(), hline.getX2()); final double x2 = Math.max(hline.getX1(), hline.getX2()); if (x2 < rect.getMinX()) { return false; } if (x1 > rect.getMaxX()) { return false; } return true; }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante .getX2(), tangeante.getY2(), tangeante.getX2(), tangeante.getY2(), inter.getX(), inter.getY()); return result.addAfter(curv); }
public void draw(Shape shape) { if (shape instanceof Line2D) { Line2D shape2d = (Line2D) shape; int width = 0; if (_stroke != null && _stroke instanceof BasicStroke) { width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700; } drawLine((int)shape2d.getX1(), (int)shape2d.getY1(), (int)shape2d.getX2(), (int)shape2d.getY2(), width); } else { if (logger.check(POILogger.WARN)) logger.log(POILogger.WARN, "draw not fully supported"); } }