/** * Creates an AffineTransformation defined by a single control vector. A * control vector consists of a source point and a destination point, which is * the image of the source point under the desired transformation. This * produces a translation. * * @param src0 * the start point of the control vector * @param dest0 * the end point of the control vector * @return the computed transformation */ public static AffineTransformation createFromControlVectors(Coordinate src0, Coordinate dest0) { double dx = dest0.x - src0.x; double dy = dest0.y - src0.y; return AffineTransformation.translationInstance(dx, dy); }
private double[] getTranslationFactors(Polygon reference, Polygon displaced) { // compare the two envelopes Envelope re = reference.getEnvelopeInternal(); Envelope de = displaced.getEnvelopeInternal(); double dw = Math.abs(re.getWidth() - de.getWidth()); double dh = Math.abs(re.getHeight() - de.getHeight()); if (dw > EPS * re.getWidth() || dh > EPS * re.getWidth()) { // this was not just a translation return null; } // compute the translation double dx = de.getMinX() - re.getMinX(); double dy = de.getMinY() - re.getMinY(); Polygon cloned = (Polygon) displaced.copy(); cloned.apply(AffineTransformation.translationInstance(-dx, -dy)); if (1 - new HausdorffSimilarityMeasure().measure(cloned, reference) > EPS) { return null; } else { return new double[] {dx, dy}; } }
/** * Updates the value of this transformation * to that of a translation transformation composed * with the current value. * * @param x the value to translate by in the x direction * @param y the value to translate by in the y direction * @return this transformation, with an updated matrix */ public AffineTransformation translate(double x, double y) { compose(translationInstance(x, y)); return this; }
public static Geometry translateToOrigin(Geometry g) { Coordinate lowerLeft = envelopeLowerLeft(g); AffineTransformation trans = AffineTransformation.translationInstance(-lowerLeft.x, -lowerLeft.y); return trans.transform(g); } }
public static Geometry translateCentreToOrigin(Geometry g) { Coordinate centre = envelopeCentre(g); AffineTransformation trans = AffineTransformation.translationInstance(-centre.x, -centre.y); return trans.transform(g); } public static Geometry translateToOrigin(Geometry g)
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); }
/** * Translates a geometry using X and Y offsets. * * @param geom Geometry * @param x X * @param y Y * @return Translated geometry */ public static Geometry translate(Geometry geom, double x, double y) { if (geom == null) { return null; } final CoordinateSequenceDimensionFilter filter = new CoordinateSequenceDimensionFilter(); geom.apply(filter); checkMixed(filter); return AffineTransformation.translationInstance(x, y).transform(geom); }
public void testTranslateRotate1() throws IOException, ParseException { AffineTransformation t = AffineTransformation.translationInstance(3, 3) .rotate(Math.PI/2); checkTransformation(10, 0, t, -3, 13); checkTransformation(-10, -10, t, 7, -7); }
public void testTranslate1() throws IOException, ParseException { AffineTransformation t = AffineTransformation.translationInstance(2, 3); checkTransformation(1, 0, t, 3, 3); checkTransformation(0, 0, t, 2, 3); checkTransformation(-10, -5, t, -8, -2); }
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); }
/** * 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; }
/** * Translates a geometry using X, Y and Z offsets. * * @param geom Geometry * @param x X * @param y Y * @param z Z * @return Translated geometry */ public static Geometry translate(Geometry geom, double x, double y, double z) { if (geom == null) { return null; } final CoordinateSequenceDimensionFilter filter = new CoordinateSequenceDimensionFilter(); geom.apply(filter); checkMixed(filter); // For all 2D geometries, we only translate by (x, y). if (filter.is2D()) { return AffineTransformation.translationInstance(x, y).transform(geom); } else { final Geometry clone = geom.copy(); clone.apply(new ZAffineTransformation(x, y, z)); return clone; } }
AffineTransformation trans = AffineTransformation.translationInstance( -src0.x, -src0.y); trans.rotate(ang);