List of usage examples for java.awt.geom AffineTransform transform
public Point2D transform(Point2D ptSrc, Point2D ptDst)
From source file:com.t_oster.visicut.misc.Helper.java
/** * Compute the rotation angle of an affine transformation. * Counter-clockwise rotation is considered positive. * * method taken from http://javagraphics.blogspot.com/ * * @return rotation angle in radians (beween -pi and pi), * or NaN if the transformation is bogus. */// w ww.j av a 2s.co m public static double getRotationAngle(AffineTransform transform) { transform = (AffineTransform) transform.clone(); // Eliminate any post-translation transform.preConcatenate( AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY())); Point2D p1 = new Point2D.Double(1, 0); p1 = transform.transform(p1, p1); return Math.atan2(p1.getY(), p1.getX()); }
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.transform(new Point(1, 2), new Point(2, 3)); g2.setTransform(at);/*from www . ja v a2s . co m*/ g2.draw(shape); }
From source file:RotateImage45Degrees.java
private AffineTransform findTranslation(AffineTransform at, BufferedImage bi) { Point2D p2din, p2dout;// w ww .j a v a 2s . co m p2din = new Point2D.Double(0.0, 0.0); p2dout = at.transform(p2din, null); double ytrans = p2dout.getY(); p2din = new Point2D.Double(0, bi.getHeight()); p2dout = at.transform(p2din, null); double xtrans = p2dout.getX(); AffineTransform tat = new AffineTransform(); tat.translate(-xtrans, -ytrans); return tat; }
From source file:com.t_oster.visicut.misc.Helper.java
/** * Returns a rectangle (parralel to x and y axis), which contains * the given rectangle after the given transform. If the transform * contains a rotation, the resulting rectangle is the smallest bounding-box * @param src//w w w .j av a 2 s . c o m * @param at * @return */ public static Rectangle2D transform(Rectangle2D src, AffineTransform at) { if (at == null) { return src; } else { java.awt.Point.Double[] points = new java.awt.Point.Double[4]; points[0] = new java.awt.Point.Double(src.getX(), src.getY()); points[1] = new java.awt.Point.Double(src.getX(), src.getY() + src.getHeight()); points[2] = new java.awt.Point.Double(src.getX() + src.getWidth(), src.getY()); points[3] = new java.awt.Point.Double(src.getX() + src.getWidth(), src.getY() + src.getHeight()); for (int i = 0; i < 4; i++) { at.transform(points[i], points[i]); } return smallestBoundingBox(points); } }
From source file:edu.uci.ics.jung.algorithms.layout.AggregateLayout.java
/** * Returns the location of the vertex. The location is specified first * by the sublayouts, and then by the base layout if no sublayouts operate * on this vertex./*w w w .ja v a2s. c o m*/ * @return the location of the vertex * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object) */ public Point2D transform(V v) { boolean wasInSublayout = false; for (Layout<V, E> layout : layouts.keySet()) { if (layout.getGraph().getVertices().contains(v)) { wasInSublayout = true; Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(center.getX() - d.width / 2, center.getY() - d.height / 2); return at.transform(layout.transform(v), null); } } if (wasInSublayout == false) { return delegate.transform(v); } return null; }
From source file:edu.uci.ics.jung.algorithms.layout.AggregateLayout.java
/** * @param v// w ww . j ava 2 s . c o m * @param location * @see edu.uci.ics.jung.algorithms.layout.Layout#setLocation(java.lang.Object, java.awt.geom.Point2D) */ public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for (Layout<V, E> layout : layouts.keySet()) { if (layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX() + d.width / 2, -center.getY() + d.height / 2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if (wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParser.java
/** * Parses a given NeatLine and Transformation matrix into a WKT String * * @param lgidict - The PDF's LGIDict object * @param neatLineArray - The NeatLine array of points for the PDF * @param toDoubleVisitor - A visitor that converts PDF Strings / Ints / Longs into doubles. * @return the generated WKT Lat/Lon set * @throws IOException/* www .j a va2s . co m*/ */ private String getWktFromNeatLine(COSDictionary lgidict, COSArray neatLineArray, ICOSVisitor toDoubleVisitor) throws IOException { List<Double> neatline = new LinkedList<>(); List<String> coordinateList = new LinkedList<>(); String firstCoordinate = null; double[] points = new double[CTM_SIZE]; for (int i = 0; i < CTM_SIZE; i++) { points[i] = (Double) lgidict.getObjectFromPath(CTM + "/[" + i + "]").accept(toDoubleVisitor); } AffineTransform affineTransform = new AffineTransform(points); for (int i = 0; i < neatLineArray.size(); i++) { neatline.add((Double) neatLineArray.get(i).accept(toDoubleVisitor)); } for (int i = 0; i < neatline.size(); i += 2) { double x = neatline.get(i); double y = neatline.get(i + 1); Point2D p = new Point2D.Double(x, y); Point2D pprime = affineTransform.transform(p, null); String xySet = point2dToWkt(pprime); if (firstCoordinate == null) { firstCoordinate = xySet; } coordinateList.add(xySet); } coordinateList.add(firstCoordinate); String wktString = StringUtils.join(coordinateList, ", "); LOGGER.debug("{}", wktString); return wktString.toString(); }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParserImpl.java
/** * Parses a given NeatLine and Transformation matrix into a WKT String * * @param lgidict - The PDF's LGIDict object * @param neatLineArray - The NeatLine array of points for the PDF * @param toDoubleVisitor - A visitor that converts PDF Strings / Ints / Longs into doubles. * @return the generated WKT Lat/Lon set * @throws IOException// ww w.j a v a 2 s .com */ private Optional<String> getWktFromNeatLine(COSDictionary lgidict, COSArray neatLineArray, ICOSVisitor toDoubleVisitor) throws IOException { List<Double> neatline = new LinkedList<>(); List<String> coordinateList = new LinkedList<>(); String firstCoordinate = null; double[] points = new double[CTM_SIZE]; for (int i = 0; i < CTM_SIZE; i++) { Object obj = lgidict.getObjectFromPath(CTM + "/[" + i + "]").accept(toDoubleVisitor); if (obj != null) { points[i] = (Double) obj; } else { return Optional.empty(); } } AffineTransform affineTransform = new AffineTransform(points); for (int i = 0; i < neatLineArray.size(); i++) { neatline.add((Double) neatLineArray.get(i).accept(toDoubleVisitor)); } for (int i = 0; i < neatline.size(); i += 2) { double x = neatline.get(i); double y = neatline.get(i + 1); Point2D p = new Point2D.Double(x, y); Point2D pprime = affineTransform.transform(p, null); String xySet = point2dToWkt(pprime); if (firstCoordinate == null) { firstCoordinate = xySet; } coordinateList.add(xySet); } coordinateList.add(firstCoordinate); String wktString = StringUtils.join(coordinateList, ", "); LOGGER.debug("{}", wktString); return Optional.of(wktString); }
From source file:edu.valelab.gaussianfit.datasettransformations.CoordinateMapper.java
/** * @param srcTestPoint//from w w w . ja v a2 s.co m * @return */ public Point2D.Double transform(Point2D.Double srcTestPoint) { if (method_ == LWM) { return computeTransformation(kdTree_, srcTestPoint, controlPoints_, exponentPairs_); } if (method_ == AFFINE) { try { if (cleanedPointMap_ == null) { cleanedPointMap_ = makeCleanedPointMap(); af_ = generateAffineTransformFromPointPairs(cleanedPointMap_); logAffineTransform(af_); ij.IJ.log("Used " + cleanedPointMap_.size() + " spot pairs to calculate 2C reference"); } return (Point2D.Double) af_.transform(srcTestPoint, null); } catch (Exception ex) { return null; } } if (method_ == NONRFEFLECTIVESIMILARITY) { try { return (Point2D.Double) rbAf_.transform(srcTestPoint, null); } catch (Exception ex) { return null; } } if (method_ == PIECEWISEAFFINE) { try { AffineTransform piecewiseAf = generateLocalAffineTransform(srcTestPoint, pieceWiseAffineMaxControlPoints_, pieceWiseAffineMaxDistance_); if (piecewiseAf != null) { Point2D result = piecewiseAf.transform(srcTestPoint, null); return (Point2D.Double) result; } } catch (Exception ex) { return null; } } return null; }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
public void createSignatureRectangle(PDSignatureField signatureField, PDFAsVisualSignatureDesigner properties, float degrees) throws IOException { PDRectangle rect = new PDRectangle(); Point2D upSrc = new Point2D.Float(); upSrc.setLocation(properties.getxAxis() + properties.getWidth(), properties.getPageHeight() - properties.getyAxis()); Point2D llSrc = new Point2D.Float(); llSrc.setLocation(properties.getxAxis(), properties.getPageHeight() - properties.getyAxis() - properties.getHeight()); rect.setUpperRightX((float) upSrc.getX()); rect.setUpperRightY((float) upSrc.getY()); rect.setLowerLeftY((float) llSrc.getY()); rect.setLowerLeftX((float) llSrc.getX()); logger.debug("orig rectangle of signature has been created: {}", rect.toString()); AffineTransform transform = new AffineTransform(); transform.setToIdentity();/* w ww . java 2s . c om*/ if (degrees % 360 != 0) { transform.setToRotation(Math.toRadians(degrees), llSrc.getX(), llSrc.getY()); } Point2D upDst = new Point2D.Float(); transform.transform(upSrc, upDst); Point2D llDst = new Point2D.Float(); transform.transform(llSrc, llDst); float xPos = properties.getxAxis(); float yPos = properties.getPageHeight() - properties.getyAxis(); logger.debug("POS {} x {}", xPos, yPos); logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight()); // translate according to page! rotation int pageRotation = properties.getPageRotation(); AffineTransform translate = new AffineTransform(); switch (pageRotation) { case 90: translate.setToTranslation( properties.getPageHeight() - (properties.getPageHeight() - properties.getyAxis()) - properties.getxAxis() + properties.getHeight(), properties.getxAxis() + properties.getHeight() - (properties.getPageHeight() - properties.getyAxis())); break; case 180: // translate.setToTranslation(properties.getPageWidth() - // properties.getxAxis() - properties.getxAxis(), // properties.getPageHeight() - properties.getyAxis() + // properties.getHeight()); translate.setToTranslation(properties.getPageWidth() - 2 * xPos, properties.getPageHeight() - 2 * (yPos - properties.getHeight())); break; case 270: translate.setToTranslation(-properties.getHeight() + yPos - xPos, properties.getPageWidth() - (yPos - properties.getHeight()) - xPos); break; } translate.transform(upDst, upDst); translate.transform(llDst, llDst); rect.setUpperRightX((float) upDst.getX()); rect.setUpperRightY((float) upDst.getY()); rect.setLowerLeftY((float) llDst.getY()); rect.setLowerLeftX((float) llDst.getX()); logger.debug("rectangle of signature has been created: {}", rect.toString()); signatureField.getWidget().setRectangle(rect); getStructure().setSignatureRectangle(rect); logger.debug("rectangle of signature has been created"); }