public Path2D.Double getPath() { if (getDel()) return null; // intentionally shadowing variables here double cx = getX(); // center double cy = getY(); double a = getA(); // left double b = getB(); double c = getC(); // top double d = getD(); // compute radius double rx = Math.hypot(a - cx, b - cy); double ry = Math.hypot(c - cx, d - cy); // compute angle of ellipse double angle = (2.0 * Math.PI + (cy > b ? 1.0 : -1.0) * Math.acos((cx - a) / rx)) % (2.0 * Math.PI); // create ellipse Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx, cy - ry, rx * 2, ry * 2); // create a path, rotate it about its center Path2D.Double path = new Path2D.Double(ellipse); AffineTransform tr = new AffineTransform(); tr.rotate(angle, cx, cy); path.transform(tr); return path; }
private Path2D.Double getTransformedDecoratorPath(Figure f, Point2D.Double p1, Point2D.Double p2) { Path2D.Double path = getDecoratorPath(f); double strokeWidth = f.get(STROKE_WIDTH); AffineTransform transform = new AffineTransform(); transform.translate(p1.x, p1.y); transform.rotate(Math.atan2(p1.x - p2.x, p2.y - p1.y)); // transform.rotate(Math.PI / 2); if (strokeWidth > 1f) { transform.scale(1d + (strokeWidth - 1d) / 2d, 1d + (strokeWidth - 1d) / 2d); } path.transform(transform); return path; }
Rectangle r = new Rectangle( x,y , width, height); Path2D.Double path = new Path2D.Double(); path.append(r, false); AffineTransform t = new AffineTransform(); t.rotate(angle); path.transform(t); g2.draw(path);
path.transform(postTransform);
path.transform(postTransform);
Double fromCurve( Curve curve, boolean close ) { Double line = new Double(); // TODO use error criterion ICRS crs = curve.getCoordinateSystem(); curve = linearizer.linearize( curve, new NumPointsCriterion( 100 ) ); curve.setCoordinateSystem( crs ); Points points = curve.getControlPoints(); Iterator<Point> iter = points.iterator(); Point p = iter.next(); double x = p.get0(), y = p.get1(); line.moveTo( x, y ); while ( iter.hasNext() ) { p = iter.next(); if ( iter.hasNext() ) { line.lineTo( p.get0(), p.get1() ); } else { if ( close && isZero( x - p.get0() ) && isZero( y - p.get1() ) ) { line.closePath(); } else { line.lineTo( p.get0(), p.get1() ); } } } line.transform( worldToScreen ); return line; }
@Override public Rectangle2D.Double getDrawingArea() { if (cachedDrawingArea == null) { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } else if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } Path2D.Double gp = (Path2D.Double) getPath(); Rectangle2D strokeRect = new Rectangle2D.Double(0, 0, width, width); if (get(TRANSFORM) != null) { gp = (Path2D.Double) gp.clone(); gp.transform(get(TRANSFORM)); strokeRect = get(TRANSFORM).createTransformedShape(strokeRect).getBounds2D(); } Rectangle2D rx = gp.getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); Geom.grow(r, strokeRect.getWidth(), strokeRect.getHeight()); cachedDrawingArea = r; } return (Rectangle2D.Double) cachedDrawingArea.clone(); }
public Path2D.Double getPath() { if (getDel()) return null; // intentionally shadowing variables here double cx = getX(); // center double cy = getY(); double a = getA(); // left double b = getB(); double c = getC(); // top double d = getD(); // compute radius double rx = Math.hypot(a - cx, b - cy); double ry = Math.hypot(c - cx, d - cy); // compute angle of ellipse double angle = (2.0 * Math.PI + (cy > b ? 1.0 : -1.0) * Math.acos((cx - a) / rx)) % (2.0 * Math.PI); // create ellipse Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx, cy - ry, rx * 2, ry * 2); // create a path, rotate it about its center Path2D.Double path = new Path2D.Double(ellipse); AffineTransform tr = new AffineTransform(); tr.rotate(angle, cx, cy); path.transform(tr); return path; }