List of usage examples for java.awt.geom AffineTransform rotate
public void rotate(double theta)
From source file:BasicShapes.java
public static void main(String[] args) { AffineTransform tx = new AffineTransform(); tx.rotate(0.5); Rectangle shape = new Rectangle(1, 1, 1, 1); Shape newShape = tx.createTransformedShape(shape); }
From source file:Main.java
public static void main(String[] args) { AffineTransform tx = new AffineTransform(); tx.rotate(0.5); Rectangle shape = new Rectangle(1, 1, 1, 1); Shape newShape = tx.createTransformedShape(shape); System.out.println("done"); }
From source file:org.eclipse.swt.snippets.Snippet361.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 361"); shell.setText("Translate and Rotate an AWT Image in an SWT GUI"); shell.setLayout(new GridLayout(8, false)); Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); fileButton.addSelectionListener(widgetSelectedAdapter(e -> { String filename = new FileDialog(shell).open(); if (filename != null) { image = Toolkit.getDefaultToolkit().getImage(filename); canvas.repaint();// ww w . j a va2s. co m } })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); translateXCombo.setItems("0", "image width", "image height", "100", "200"); translateXCombo.select(0); translateXCombo.addModifyListener(e -> { translateX = numericValue(translateXCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("Translate &Y by:"); final Combo translateYCombo = new Combo(shell, SWT.NONE); translateYCombo.setItems("0", "image width", "image height", "100", "200"); translateYCombo.select(0); translateYCombo.addModifyListener(e -> { translateY = numericValue(translateYCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("&Rotate by:"); final Combo rotateCombo = new Combo(shell, SWT.NONE); rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8"); rotateCombo.select(0); rotateCombo.addModifyListener(e -> { rotate = numericValue(rotateCombo); canvas.repaint(); }); Button printButton = new Button(shell, SWT.PUSH); printButton.setText("&Print Image"); printButton.addSelectionListener(widgetSelectedAdapter(e -> { performPrintAction(display, shell); })); composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1); data.widthHint = 640; data.heightHint = 480; composite.setLayoutData(data); Frame frame = SWT_AWT.new_Frame(composite); canvas = new Canvas() { @Override public void paint(Graphics g) { if (image != null) { g.setColor(Color.WHITE); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); /* Use Java2D here to modify the image as desired. */ Graphics2D g2d = (Graphics2D) g; AffineTransform t = new AffineTransform(); t.translate(translateX, translateY); t.rotate(rotate); g2d.setTransform(t); /*------------*/ g.drawImage(image, 0, 0, this); } } }; frame.add(canvas); composite.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = "Image drawn in AWT Canvas"; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Main.java
private static AffineTransform createRandomTransform(double angleRad) { AffineTransform at = new AffineTransform(); double scale = 1.0; at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale);//w ww .ja v a 2s. co m at.rotate(angleRad); at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale); return at; }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) { if (sides < 3) { return new Ellipse2D.Float(0, 0, 10, 10); }/* ww w . j a v a 2 s. c o m*/ AffineTransform trans = new AffineTransform(); Polygon poly = new Polygon(); for (int i = 0; i < sides; i++) { trans.rotate(Math.PI * 2 / (float) sides / 2); Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null); poly.addPoint((int) out.getX(), (int) out.getY()); trans.rotate(Math.PI * 2 / (float) sides / 2); if (insideRadius > 0) { Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null); poly.addPoint((int) in.getX(), (int) in.getY()); } } return poly; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawArcTest(Graphics2D g2) { g2.setPaint(Color.GREEN);/*from w w w .j a va2s . c om*/ g2.drawRect(0, 20, 70, 50); g2.setPaint(Color.RED); Path2D path1 = new Path2D.Double(); double[] pts = calculateReferenceArc(90); path1.moveTo(pts[0], pts[1]); path1.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t = new AffineTransform(); t.translate(35, 45); t.scale(35, 25); t.rotate(Math.PI / 4); path1.transform(t); g2.draw(path1); Path2D path2 = new Path2D.Double(); path2.moveTo(pts[0], pts[1]); path2.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t2 = new AffineTransform(); t2.rotate(3 * Math.PI / 4); t2.scale(35, 25); t2.translate(35, 35); path2.transform(t2); //g2.draw(path2); Path2D arc = new Path2D.Double(); arc.append(path1, false); arc.append(path2, false); //g2.draw(arc); //g2.draw(path1); //g2.transform(t); g2.setPaint(Color.BLUE); g2.drawArc(0, 20, 70, 50, 0, -270); //Arc2D arc2d = new Arc2D.Double(0d, 20d, 70d, 50d, 0d, 90, Arc2D.OPEN); //g2.draw(arc2d); }
From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java
/** * get the right transformation based on the orientation setting in the exif metadata. In case the physical image is actually * stored in a rotated state.//from w w w . j a v a 2 s. c o m * * @param orientation * @param width * @param height * @return */ public static AffineTransform getExifTransformation(int orientation, double width, double height, double scaleW, double scaleH) { AffineTransform t = new AffineTransform(); switch (orientation) { case 1: t.scale(scaleW, scaleH); break; case 2: // Flip X //todo: test & fix t.scale(-scaleW, scaleH); t.translate(-width, 0); break; case 3: // PI rotation t.translate(width, height); t.rotate(Math.PI); t.scale(scaleW, scaleH); break; case 4: // Flip Y //todo: test & fix t.scale(scaleW, -scaleH); t.translate(0, -height); break; case 5: // - PI/2 and Flip X t.rotate(-Math.PI / 2); t.scale(-scaleW, scaleH); break; case 6: // -PI/2 and -width t.translate(height, 0); t.rotate(Math.PI / 2); t.scale(scaleW, scaleH); break; case 7: // PI/2 and Flip //todo:test & fix t.scale(-scaleW, scaleH); t.translate(-height, 0); t.translate(0, width); t.rotate(3 * Math.PI / 2); break; case 8: // PI / 2 t.translate(0, width); t.rotate(3 * Math.PI / 2); t.scale(scaleW, scaleH); break; } return t; }
From source file:de.bund.bfr.jung.JungUtils.java
static <V, E> Shape getTransformedEdgeShape(RenderContext<V, E> rc, Layout<V, E> layout, E e) { Graph<V, E> graph = layout.getGraph(); edu.uci.ics.jung.graph.util.Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst();/* w w w. j a va 2 s.co m*/ V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(graph, e)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) { return null; } Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.getInstance(graph, e)); AffineTransform edgeShapeTransform = AffineTransform.getTranslateInstance(x1, y1); if (v1.equals(v2)) { Rectangle2D bounds = rc.getVertexShapeTransformer().transform(v1).getBounds2D(); edgeShapeTransform.scale(bounds.getWidth(), bounds.getHeight()); edgeShapeTransform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; edgeShapeTransform.rotate(Math.atan2(dy, dx)); edgeShapeTransform.scale(Math.sqrt(dx * dx + dy * dy), 1.0); } return edgeShapeTransform.createTransformedShape(edgeShape); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);//from w ww . j a v a2s . c o m po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:Main.java
public void paint(Graphics g) { Shape shape = new Rectangle2D.Float(100, 50, 80, 80); Graphics2D g2 = (Graphics2D) g; AffineTransform at = new AffineTransform(); at.rotate(0.5); g2.setTransform(at);//from w w w . jav a 2 s. c o m g2.draw(shape); }