/** * Creates a transformation for a scaling relative to the point (x,y). * * @param xScale the value to scale by in the x direction * @param yScale the value to scale by in the y direction * @param x the x-ordinate of the point to scale around * @param y the y-ordinate of the point to scale around * @return a transformation for the scaling */ public static AffineTransformation scaleInstance(double xScale, double yScale, double x, double y) { AffineTransformation trans = new AffineTransformation(); trans.translate(-x, -y); trans.scale(xScale, yScale); trans.translate(x, y); return trans; }
translate(x0, y0); return this;
private static AffineTransformation viewportTrans(Envelope srcEnv, Envelope viewEnv) { // works even if W or H are zero, thanks to Java infinity value. double scaleW = viewEnv.getWidth() / srcEnv.getWidth(); double scaleH = viewEnv.getHeight() / srcEnv.getHeight(); // choose minimum scale to ensure source fits viewport double scale = Math.min(scaleW, scaleH); Coordinate centre = srcEnv.centre(); Coordinate viewCentre = viewEnv.centre(); // isotropic scaling AffineTransformation trans = AffineTransformation.scaleInstance(scale, scale, centre.x, centre.y); // translate using envelope centres trans.translate(viewCentre.x - centre.x, viewCentre.y - centre.y); return trans; }
public void testCompose3() { AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 10, 10, 0); t0.translate(-10, -10); AffineTransformation t1 = AffineTransformation.reflectionInstance(0, 0, -1, 1); checkTransformation(t0, t1); }
public void testComposeRotation1() { AffineTransformation t0 = AffineTransformation.rotationInstance(1, 10, 10); AffineTransformation t1 = AffineTransformation.translationInstance(-10, -10); t1.rotate(1); t1.translate(10, 10); checkTransformation(t0, t1); }
public void testTransform1() { AffineTransformation trans = new AffineTransformation(); trans.rotate(1); trans.translate(10, 10); trans.scale(2, 2); runTransform(trans, ctl0, ctl1, ctl2); }
public void testCompose1() { AffineTransformation t0 = AffineTransformation.translationInstance(10, 0); t0.rotate(Math.PI /2); t0.translate(0, -10); AffineTransformation t1 = AffineTransformation.translationInstance(0, 0); t1.rotate(Math.PI /2); checkTransformation(t0, t1); }
/** * Creates an AffineTransformation defined by a pair of control vectors. A * control vector consists of a source point and a destination point, which is * the image of the source point under the desired transformation. The * computed transformation is a combination of one or more of a uniform scale, * a rotation, and a translation (i.e. there is no shear component and no * reflection) * * @param src0 * @param src1 * @param dest0 * @param dest1 * @return the computed transformation, or null if the control vectors do not determine a well-defined transformation */ public static AffineTransformation createFromControlVectors(Coordinate src0, Coordinate src1, Coordinate dest0, Coordinate dest1) { Coordinate rotPt = new Coordinate(dest1.x - dest0.x, dest1.y - dest0.y); double ang = Angle.angleBetweenOriented(src1, src0, rotPt); double srcDist = src1.distance(src0); double destDist = dest1.distance(dest0); if (srcDist == 0.0) return null; double scale = destDist / srcDist; AffineTransformation trans = AffineTransformation.translationInstance( -src0.x, -src0.y); trans.rotate(ang); trans.scale(scale, scale); trans.translate(dest0.x, dest0.y); return trans; }
trans.rotate(ang); trans.scale(scale, scale); trans.translate(dest0.x, dest0.y); return trans;
public void testTransform2() { AffineTransformation trans = new AffineTransformation(); trans.rotate(3); trans.translate(10, 10); trans.scale(2, 10); trans.shear(5, 2); trans.reflect(5, 8, 10, 2); runTransform(trans, ctl0, ctl1, ctl2); }