List of usage examples for java.awt.geom AffineTransform transform
public Point2D transform(Point2D ptSrc, Point2D ptDst)
From source file:Main.java
private static double extractAngle(AffineTransform at) { Point2D p0 = new Point(); Point2D p1 = new Point(1, 0); Point2D pp0 = at.transform(p0, null); Point2D pp1 = at.transform(p1, null); double dx = pp1.getX() - pp0.getX(); double dy = pp1.getY() - pp0.getY(); double angle = Math.atan2(dy, dx); return angle; }
From source file:Main.java
public static Point2D.Double toSheetPoint(Point2D pScreen, AffineTransform at) { Point2D.Double pWorld = new Point2D.Double(); AffineTransform at1; try {//from ww w.j a va2 s .co m at1 = at.createInverse(); at1.transform(pScreen, pWorld); } catch (NoninvertibleTransformException e) { } return pWorld; }
From source file:Main.java
public static Point2D.Double fromSheetPoint(Point2D pSheet, AffineTransform at) { Point2D.Double pScreen = new Point2D.Double(); try {//w ww . j a va 2s. c o m at.transform(pSheet, pScreen); } catch (Exception e) { System.err.print(e.getMessage()); } return pScreen; }
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); }//w w w .j a v a2 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:Main.java
public static double fromSheetDistance(double d, AffineTransform at) { Point2D.Double pSheet1 = new Point2D.Double(0, 0); Point2D.Double pSheet2 = new Point2D.Double(1, 0); Point2D.Double pScreen1 = new Point2D.Double(); Point2D.Double pScreen2 = new Point2D.Double(); try {/*from w w w .j a v a 2s .com*/ at.transform(pSheet1, pScreen1); at.transform(pSheet2, pScreen2); } catch (Exception e) { System.err.print(e.getMessage()); } return pScreen1.distance(pScreen2) * d; }
From source file:Main.java
public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) { Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY()); Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY()); Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY()); Point2D.Double pScreen = new Point2D.Double(); Point2D.Double pScreenX = new Point2D.Double(); Point2D.Double pScreenY = new Point2D.Double(); try {/*from www . j a v a2s. co m*/ at.transform(pSheet, pScreen); at.transform(pSX, pScreenX); at.transform(pSY, pScreenY); } catch (Exception e) { System.err.print(e.getMessage()); } Rectangle2D.Double res = new Rectangle2D.Double(); res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY)); return res; }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity//from w w w . ja v a 2 s. c o m * @param chartPanel * @return */ public static Point2D toViewXY(Point2D entity, ChartPanel chartPanel) { AffineTransform toPosition = getModelToViewTransformXY(chartPanel, entity.getX(), entity.getY()); toPosition.concatenate(getTranslateInstance(-entity.getX(), -entity.getY())); return toPosition.transform(entity, null); }
From source file:MathFunctions.java
public static AffineTransform generateAffineTransformFromPointPairs( Map<Point2D.Double, Point2D.Double> pointPairs, double srcTol, double destTol) throws Exception { AffineTransform transform = generateAffineTransformFromPointPairs(pointPairs); double srcDevSqSum = 0; double destDevSqSum = 0; for (Map.Entry pair : pointPairs.entrySet()) { try {//from w w w. j ava 2 s . c o m Point2D.Double srcPt = (Point2D.Double) pair.getKey(); Point2D.Double destPt = (Point2D.Double) pair.getValue(); Point2D.Double srcPt2 = (Point2D.Double) transform.inverseTransform(destPt, null); Point2D.Double destPt2 = (Point2D.Double) transform.transform(srcPt, null); srcDevSqSum += srcPt.distanceSq(srcPt2); destDevSqSum += destPt.distanceSq(destPt2); } catch (NoninvertibleTransformException ex) { throw new Exception(); } } int n = pointPairs.size(); double srcRMS = Math.sqrt(srcDevSqSum / n); double destRMS = Math.sqrt(destDevSqSum / n); if (srcRMS > srcTol || destRMS > destTol) { throw new Exception("Point mapping scatter exceeds tolerance."); } return transform; }
From source file:MathFunctions.java
public static void runAffineTest() { Map<Point2D.Double, Point2D.Double> pointPairs = new HashMap<Point2D.Double, Point2D.Double>(); // Create sample src and dest points: pointPairs.put(new Point2D.Double(1, 1), new Point2D.Double(18, 2)); pointPairs.put(new Point2D.Double(1, 9), new Point2D.Double(2, 2)); pointPairs.put(new Point2D.Double(9, 9), new Point2D.Double(2, 18)); pointPairs.put(new Point2D.Double(9, 1), new Point2D.Double(18, 18)); // Run the computation to be tested: AffineTransform affineTransform = generateAffineTransformFromPointPairs(pointPairs); // Print input and output: System.out.println(pointPairs); System.out.println(affineTransform); int i = 0;//www . j a v a 2s. c o m // Check that affineTransform works correctly: for (Map.Entry pair : pointPairs.entrySet()) { Point2D.Double uPt = (Point2D.Double) pair.getKey(); Point2D.Double vPt = (Point2D.Double) pair.getValue(); Point2D.Double result = new Point2D.Double(); affineTransform.transform(uPt, result); System.out.println(uPt + "->" + result + " residual: " + vPt.distance(result)); i++; } }
From source file:com.t_oster.visicut.misc.Helper.java
/** * Returns an AffineTransform, which transformes src to dest * and constists of a scale and translate component * @param src// w ww .j a v a2s .com * @param dest * @return */ public static AffineTransform getTransform(Rectangle2D src, Rectangle2D dest) { AffineTransform scale = AffineTransform.getScaleInstance(dest.getWidth() / src.getWidth(), dest.getHeight() / src.getHeight()); Point2D scaled = scale.transform(new Point.Double(src.getX(), src.getY()), null); AffineTransform result = AffineTransform.getTranslateInstance(dest.getX() - scaled.getX(), dest.getY() - scaled.getY()); result.concatenate(scale); return result; }