List of usage examples for java.awt.geom AffineTransform transform
public Point2D transform(Point2D ptSrc, Point2D ptDst)
From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java
private PixelPos getProductCenter(final Product product) { final GeoCoding geoCoding = product.getSceneGeoCoding(); PixelPos centerPos = null;/*from w w w . j a va2 s . c o m*/ if (geoCoding != null) { final float pixelX = (float) Math.floor(0.5f * product.getSceneRasterWidth()) + 0.5f; final float pixelY = (float) Math.floor(0.5f * product.getSceneRasterHeight()) + 0.5f; final GeoPos geoPos = geoCoding.getGeoPos(new PixelPos(pixelX, pixelY), null); final AffineTransform transform = layerCanvas.getViewport().getModelToViewTransform(); final Point2D point2D = transform.transform(new Point2D.Double(geoPos.getLon(), geoPos.getLat()), null); centerPos = new PixelPos((float) point2D.getX(), (float) point2D.getY()); } return centerPos; }
From source file:org.jcurl.core.base.Collider.java
/** * Check distance, speed of approach, transform speeds to rock-coordinates, * call {@link #computeRC(Rock, Rock)}and transform back to wc afterwards. * /*from w ww .j av a 2 s . c o m*/ * @param xa * @param xb * @param va * @param vb * @param mat * may be null. If not avoids frequent instanciations * @return <code>true</code> hit, <code>false</code> no hit. */ public boolean computeWC(final Rock xa, final Rock xb, final Rock va, final Rock vb, AffineTransform mat) { if (mat == null) mat = new AffineTransform(); // check distance if (xa.distanceSq(xb) > MaxDistSq) { if (log.isDebugEnabled()) log.debug("Too far away distance=" + (xa.distance(xb) - (_Rad + _Rad))); return false; } // change the coordinate system to rock-coordinates final Rock _va = (Rock) va.clone(); final Rock _vb = (Rock) vb.clone(); getInverseTrafo(vb, xa, xb, mat); try { // transform mat.inverseTransform(va, _va); mat.inverseTransform(vb, _vb); } catch (NoninvertibleTransformException e) { throw new RuntimeException("Matrix must be invertible", e); } // check speed of approach if (!_va.nonZero()) return false; if (log.isDebugEnabled()) log.debug("hit!"); // physical model computeRC(_va, _vb); // re-transform mat.transform(_va, va); va.setZ(_va.getZ()); mat.transform(_vb, vb); vb.setZ(_vb.getZ()); return true; }
From source file:org.jcurl.core.base.ColliderBase.java
/** * Check distance, speed of approach, transform speeds to rock-coordinates, * call {@link #computeRC(Rock, Rock)}and transform back to wc afterwards. * // w w w . ja va2 s . co m * @param xa * @param xb * @param va * @param vb * @param mat * may be null. If not avoids frequent instanciations * @return <code>true</code> hit, <code>false</code> no hit. */ protected boolean computeWC(final Rock xa, final Rock xb, final Rock va, final Rock vb, AffineTransform mat) { if (mat == null) mat = new AffineTransform(); // check distance if (xa.distanceSq(xb) > MaxDistSq) { if (log.isDebugEnabled()) log.debug("Too far away distance=" + (xa.distance(xb) - (_Rad + _Rad))); return false; } // change the coordinate system to rock-coordinates final Rock _va = (Rock) va.clone(); final Rock _vb = (Rock) vb.clone(); getInverseTrafo(vb, xa, xb, mat); try { // transform mat.inverseTransform(va, _va); mat.inverseTransform(vb, _vb); } catch (final NoninvertibleTransformException e) { throw new RuntimeException("Matrix must be invertible", e); } // check speed of approach if (!_va.nonZero()) return false; if (log.isDebugEnabled()) log.debug("hit!"); // physical model computeRC(_va, _vb); // re-transform mat.transform(_va, va); va.setZ(_va.getZ()); // FIXME apply angle delta from Collission coordinates to WC mat.transform(_vb, vb); vb.setZ(_vb.getZ()); // FIXME apply angle delta from Collission coordinates to WC return true; }
From source file:org.jcurl.core.base.CollissionStrategy.java
/** * Check distance, speed of approach, transform speeds to rock-coordinates, * call {@link #computeRC(Rock, Rock)}and transform back to wc afterwards. * //from w w w. j a v a 2 s . c o m * @param xa * @param xb * @param va * @param vb * @param mat * may be null. If not avoids frequent instanciations * @return <code>true</code> hit, <code>false</code> no hit. */ protected boolean computeWC(final Rock xa, final Rock xb, final Rock va, final Rock vb, AffineTransform mat) { if (mat == null) mat = new AffineTransform(); // check distance if (xa.distanceSq(xb) > MaxDistSq) { if (log.isDebugEnabled()) log.debug("Too far away distance=" + (xa.distance(xb) - (_Rad + _Rad))); return false; } // change the coordinate system to rock-coordinates final Rock _va = (Rock) va.clone(); final Rock _vb = (Rock) vb.clone(); getInverseTrafo(vb, xa, xb, mat); try { // transform mat.inverseTransform(va, _va); mat.inverseTransform(vb, _vb); } catch (NoninvertibleTransformException e) { throw new RuntimeException("Matrix must be invertible", e); } // check speed of approach if (!_va.nonZero()) return false; if (log.isDebugEnabled()) log.debug("hit!"); // physical model computeRC(_va, _vb); // re-transform mat.transform(_va, va); va.setZ(_va.getZ()); mat.transform(_vb, vb); vb.setZ(_vb.getZ()); return true; }
From source file:org.jcurl.core.base.CurveTransformedTest.java
public void testAffineTransformMemoryLayout() { Rock r = new RockDouble(1, 2, 3); AffineTransform at = new AffineTransform(); final double[] d = new double[6]; at.getMatrix(d);//from w w w .j a va 2 s . com assertEquals("", 1.0, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 1.0, d[3], 1e-9); assertEquals("", 0.0, d[4], 1e-9); assertEquals("", 0.0, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(2, 3, 4, r, 1e-9); at = AffineTransform.getScaleInstance(0.5, 0.75); at.getMatrix(d); assertEquals("", 0.5, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 0.75, d[3], 1e-9); assertEquals("", 0.0, d[4], 1e-9); assertEquals("", 0.0, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(1, 2.25, 4, r, 1e-9); at = AffineTransform.getTranslateInstance(0.5, 0.75); at.getMatrix(d); assertEquals("", 1.0, d[0], 1e-9); assertEquals("", 0.0, d[1], 1e-9); assertEquals("", 0.0, d[2], 1e-9); assertEquals("", 1.0, d[3], 1e-9); assertEquals("", 0.5, d[4], 1e-9); assertEquals("", 0.75, d[5], 1e-9); at.transform(r = new RockDouble(2, 3, 4), r); assertEquals(2.5, 3.75, 4, r, 1e-9); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
public void testAffineTransformRotate() { final Rock v0 = new RockDouble(1, 1.5, 0.3); final double[] d = { v0.getY(), -v0.getX(), v0.getX(), v0.getY(), 0, 0 }; final AffineTransform at = new AffineTransform(d); final double v = v0.distance(0, 0); at.scale(1 / v, 1 / v);/*from w w w. ja v a2 s . c om*/ assertEquals(AffineTransform.TYPE_GENERAL_ROTATION, at.getType()); assertEquals("", 1.0, at.getDeterminant(), 1e-9); assertEquals("", 0.8320502943378437, at.getScaleX(), 1e-9); assertEquals("", at.getScaleX(), at.getScaleY(), 1e-9); assertEquals("", 0.5547001962252291, at.getShearX(), 1e-9); assertEquals("", -at.getShearX(), at.getShearY(), 1e-9); assertEquals("", 0.0, at.getTranslateX(), 1e-9); assertEquals("", 0.0, at.getTranslateY(), 1e-9); Point2D p = null; p = at.transform(new Point2D.Double(1, 0), null); assertEquals("Point2D.Double[0.8320502943378437, -0.5547001962252291]", p.toString()); assertEquals("", 1.0, p.distanceSq(0, 0), 1e-9); p = at.transform(new Point2D.Double(0, 1), null); assertEquals("Point2D.Double[0.5547001962252291, 0.8320502943378437]", p.toString()); assertEquals("", 1.0, p.distanceSq(0, 0), 1e-9); p = at.transform(new Point2D.Double(0.75, 1.5), null); assertEquals("Point2D.Double[1.4560880150912265, 0.8320502943378438]", p.toString()); p = at.transform(new Point2D.Double(1.5, 3.0), null); assertEquals("Point2D.Double[2.912176030182453, 1.6641005886756877]", p.toString()); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5)./* ww w . j av a 2s . c om*/ */ public void testAffineTransformRotateShift() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final double v = v0_wc.distance(0, 0); final double[] d = { v0_wc.getY(), -v0_wc.getX(), v0_wc.getX(), v0_wc.getY(), 0, 0 }; final AffineTransform at = new AffineTransform(d); at.scale(1 / v, 1 / v); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_UNIFORM_SCALE, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(0, at.getTranslateX()); assertEquals(0, at.getTranslateY()); Point2D p = null; p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[5.073216248629703, -0.9759492274906292]", p.toString()); at.preConcatenate(AffineTransform.getTranslateInstance(p0_wc.getX(), p0_wc.getY())); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION + AffineTransform.TYPE_UNIFORM_SCALE, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); p = at.transform(new Point2D.Double(5, 1.3), null); assertEquals("Point2D.Double[8.073216248629702, 2.524050772509371]", p.toString()); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5).// ww w . ja v a 2 s . c om * * @see CurveTransformed#createRc2Wc(AffineTransform, Point2D, Point2D) */ public void testCreateRc2Wc() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final AffineTransform at = CurveTransformed.createRc2Wc(null, p0_wc, v0_wc); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); final Point2D rc = new Point2D.Double(5, 1.3); final Point2D wc = at.transform(rc, null); assertEquals("Point2D.Double[8.073216248629704, 2.524050772509371]", wc.toString()); // angle in rc: double ang = Math.atan2(rc.getY(), rc.getX()); assertEquals(14.574216198038739, rad2deg(ang)); // wc rotation: ang = Math.atan2(at.getShearY(), at.getScaleY()); assertEquals(-25.463345061871614, rad2deg(ang)); final double[] d = new double[6]; at.getMatrix(d); ang = Math.atan2(-d[2], d[3]); assertEquals(-25.463345061871614, rad2deg(ang)); // angle in wc: ang = Math.atan2(wc.getY(), wc.getX()); assertEquals(17.36159358309492, rad2deg(ang)); }
From source file:org.jcurl.core.impl.ColliderBase.java
/** * Check distance, speed of approach, transform speeds to * collission-coordinates, call {@link #computeCC(Rock, Rock)} and transform * back to wc afterwards.//from ww w.j av a2s . co m * <p> * The angle (not the angular speed!) remains in WC and untouched! * </p> * * @param xa * position before the hit (WC) * @param xb * position before the hit (WC) * @param va * speed before the hit (CC) * @param vb * speed before the hit (usually zero) * @param mat * may be null. If not avoids frequent instanciations * @return <code>true</code> hit, <code>false</code> no hit. */ protected boolean computeWC(final Rock<Pos> xa, final Rock<Pos> xb, final Rock<Vel> va, final Rock<Vel> vb, AffineTransform mat) { if (mat == null) mat = new AffineTransform(); // check distance if (xa.p().distanceSq(xb.p()) > MaxDistSq) { if (log.isDebugEnabled()) log.debug("Too far away distance=" + (xa.p().distance(xb.p()) - (_Rad + _Rad))); return false; } // change the coordinate system to collission-coordinates final Rock<Vel> _va = (Rock<Vel>) va.clone(); final Rock<Vel> _vb = (Rock<Vel>) vb.clone(); getInverseTrafo(vb.p(), xa.p(), xb.p(), mat); try { // transform mat.inverseTransform(va.p(), _va.p()); mat.inverseTransform(vb.p(), _vb.p()); } catch (final NoninvertibleTransformException e) { throw new RuntimeException("Matrix must be invertible", e); } // check speed of approach if (!_va.isNotZero()) return false; if (log.isDebugEnabled()) log.debug("hit!"); // physical model computeCC(_va, _vb); // re-transform mat.transform(_va.p(), va.p()); va.setA(_va.getA()); mat.transform(_vb.p(), vb.p()); vb.setA(_vb.getA()); return true; }
From source file:org.jcurl.model.PathSegmentTest.java
public void testTrafo() throws NoninvertibleTransformException { final Point2D x0 = new Point2D.Double(1.5, 2.5); // final Point2D x0 = new Point2D.Double(0, 0); final Point2D v0 = new Point2D.Double(2, 1); // build the trafo final AffineTransform rc2wc = new AffineTransform(); {/*w ww .j a va 2 s .c o m*/ rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / v0.distance(0, 0)), x0.getX(), x0.getY()); rc2wc.translate(x0.getX(), x0.getY()); } // check some points. // wc(x0) -> rc(0,0) Point2D tmp = rc2wc.inverseTransform(x0, null); assertEquals("", 0, tmp.getX(), 1e-9); assertEquals("", 0, tmp.getY(), 1e-9); // rc(0,1) -> wc(x0) tmp = rc2wc.transform(new Point2D.Double(0, 1), null); assertEquals("", x0.getX() + 0.8944271909999, tmp.getX(), 1e-6); assertEquals("", x0.getY() + 0.4472135954999, tmp.getY(), 1e-6); }