List of usage examples for java.awt.geom AffineTransform getDeterminant
@SuppressWarnings("fallthrough") public double getDeterminant()
From source file:MathFunctions.java
public static double getScalingFactor(AffineTransform transform) { return Math.sqrt(Math.abs(transform.getDeterminant())); }
From source file:DefaultGraphics2D.java
/** * Renders an image, applying a transform from image space into user space * before drawing. The transformation from user space into device space is * done with the current <code>Transform</code> in the * <code>Graphics2D</code>. The specified transformation is applied to the * image before the transform attribute in the <code>Graphics2D</code> * context is applied. The rendering attributes applied include the * <code>Clip</code>, <code>Transform</code>, and <code>Composite</code> * attributes. Note that no rendering is done if the specified transform is * noninvertible.//w ww .j a va2s .c o m * * @param img * the <code>Image</code> to be rendered * @param xform * the transformation from image space into user space * @param obs * the {@link ImageObserver} to be notified as more of the * <code>Image</code> is converted * @return <code>true</code> if the <code>Image</code> is fully loaded and * completely rendered; <code>false</code> if the <code>Image</code> * is still being loaded. * @see #transform * @see #setTransform * @see #setComposite * @see #clip * @see #setClip(Shape) */ public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { boolean retVal = true; if (xform.getDeterminant() != 0) { AffineTransform inverseTransform = null; try { inverseTransform = xform.createInverse(); } catch (NoninvertibleTransformException e) { // Should never happen since we checked the // matrix determinant throw new Error(e.getMessage()); } gc.transform(xform); retVal = drawImage(img, 0, 0, null); gc.transform(inverseTransform); } else { AffineTransform savTransform = new AffineTransform(gc.getTransform()); gc.transform(xform); retVal = drawImage(img, 0, 0, null); gc.setTransform(savTransform); } return retVal; }
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 ww w . ja v a2 s . co m 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).//from ww w . ja va 2 s .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)./*from www.j av a2 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)); }