/** * Creates a transformation for a rotation * about the origin * by an angle <i>theta</i>. * Positive angles correspond to a rotation * in the counter-clockwise direction. * * @param theta the rotation angle, in radians * @return a transformation for the rotation */ public static AffineTransformation rotationInstance(double theta) { return rotationInstance(Math.sin(theta), Math.cos(theta)); }
/** * Creates a transformation for a rotation * about the point (x,y) by an angle <i>theta</i>. * Positive angles correspond to a rotation * in the counter-clockwise direction. * * @param theta the rotation angle, in radians * @param x the x-ordinate of the rotation point * @param y the y-ordinate of the rotation point * @return a transformation for the rotation */ public static AffineTransformation rotationInstance(double theta, double x, double y) { return rotationInstance(Math.sin(theta), Math.cos(theta), x, y); }
/** * Updates the value of this transformation * to that of a rotation around the origin composed * with the current value, * with the sin and cos of the rotation angle specified directly. * * @param sinTheta the sine of the angle to rotate by * @param cosTheta the cosine of the angle to rotate by * @return this transformation, with an updated matrix */ public AffineTransformation rotate(double sinTheta, double cosTheta) { compose(rotationInstance(sinTheta, cosTheta)); return this; }
/** * Updates the value of this transformation * to that of a rotation transformation composed * with the current value. * Positive angles correspond to a rotation * in the counter-clockwise direction. * * @param theta the angle to rotate by, in radians * @return this transformation, with an updated matrix */ public AffineTransformation rotate(double theta) { compose(rotationInstance(theta)); return this; }
/** * Updates the value of this transformation * to that of a rotation around a given point composed * with the current value. * Positive angles correspond to a rotation * in the counter-clockwise direction. * * @param theta the angle to rotate by, in radians * @param x the x-ordinate of the rotation point * @param y the y-ordinate of the rotation point * @return this transformation, with an updated matrix */ public AffineTransformation rotate(double theta, double x, double y) { compose(rotationInstance(theta, x, y)); return this; }
/** * Updates the value of this transformation * to that of a rotation around a given point composed * with the current value, * with the sin and cos of the rotation angle specified directly. * * @param sinTheta the sine of the angle to rotate by * @param cosTheta the cosine of the angle to rotate by * @param x the x-ordinate of the rotation point * @param y the y-ordinate of the rotation point * @return this transformation, with an updated matrix */ public AffineTransformation rotate(double sinTheta, double cosTheta, double x, double y) { compose(rotationInstance(sinTheta, cosTheta, x, y)); return this; }
/** * Rotates a geometry by a given angle (in radians) about the specified * point at (x0, y0). * * @param geom Geometry * @param theta Angle * @param x0 x-coordinate of point about which to rotate * @param y0 y-coordinate of point about which to rotate * @return The geometry rotated by theta about (x0, y0) */ public static Geometry rotate(Geometry geom, double theta, double x0, double y0) { if (geom != null) { return AffineTransformation.rotationInstance(theta, x0, y0).transform(geom); } else { return null; } } }
protected Geometry rotate(Geometry geom) { if (rotationAngle != 0.0) { AffineTransformation trans = AffineTransformation.rotationInstance(rotationAngle, dim.getCentre().x, dim.getCentre().y); geom.apply(trans); } return geom; }
@Metadata(description="Rotate a geometry by an multiple of Pi radians") public static Geometry rotateByPiMultiple(Geometry g, @Metadata(title="Angle (multiple of Pi)") double multipleOfPi) { Coordinate centre = envelopeCentre(g); AffineTransformation trans = AffineTransformation.rotationInstance(multipleOfPi * Math.PI, centre.x, centre.y); return trans.transform(g); }
@Metadata(description="Rotate a geometry by an angle in radians") public static Geometry rotate(Geometry g, @Metadata(title="Angle (radians)") double angle) { Coordinate centre = envelopeCentre(g); AffineTransformation trans = AffineTransformation.rotationInstance(angle, centre.x, centre.y); return trans.transform(g); }
@Metadata(description="Rotate a geometry around a point by an multiple of Pi radians") public static Geometry rotateByPiMultipleAroundPoint(Geometry g, Geometry pt, @Metadata(title="Angle (multiple of Pi)") double multipleOfPi) { Coordinate loc; if (pt == null) { loc = new Coordinate(0,0); } else { loc = pt.getCoordinates()[0]; } AffineTransformation trans = AffineTransformation.rotationInstance(multipleOfPi * Math.PI, loc.x, loc.y); return trans.transform(g); }
@Metadata(description="Rotate a geometry around a point by an angle in radians") public static Geometry rotateAroundPoint(Geometry g, Geometry pt, @Metadata(title="Angle (radians)") double angle) { Coordinate loc; if (pt == null) { loc = new Coordinate(0,0); } else { loc = pt.getCoordinates()[0]; } AffineTransformation trans = AffineTransformation.rotationInstance(angle, loc.x, loc.y); return trans.transform(g); }
public void testCompose2() { AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 0, 1, 0); t0.reflect(0, 0, 0, -1); AffineTransformation t1 = AffineTransformation.rotationInstance(Math.PI); checkTransformation(t0, t1); }
public void testRotate2() throws IOException, ParseException { AffineTransformation t = AffineTransformation.rotationInstance(1, 0); checkTransformation(10, 0, t, 0, 10); checkTransformation(0, 10, t, -10, 0); checkTransformation(-10, -10, t, 10, -10); }
public void testRotate1() throws IOException, ParseException { AffineTransformation t = AffineTransformation.rotationInstance(Math.PI/2); checkTransformation(10, 0, t, 0, 10); checkTransformation(0, 10, t, -10, 0); checkTransformation(-10, -10, t, 10, -10); }
public void testRotateAroundPoint1() throws IOException, ParseException { AffineTransformation t = AffineTransformation.rotationInstance(Math.PI/2, 1, 1); checkTransformation(1, 1, t, 1, 1); checkTransformation(10, 0, t, 2, 10); checkTransformation(0, 10, t, -8, 0); checkTransformation(-10, -10, t, 12, -10); }
public void testRotateAroundPoint2() throws IOException, ParseException { AffineTransformation t = AffineTransformation.rotationInstance(1, 0, 1, 1); checkTransformation(1, 1, t, 1, 1); checkTransformation(10, 0, t, 2, 10); checkTransformation(0, 10, t, -8, 0); checkTransformation(-10, -10, t, 12, -10); }
public static MultiPolygon crossedComb(Envelope env, int size, GeometryFactory geomFact) { Polygon comb1 = comb(env, size, geomFact); Coordinate centre = env.centre(); AffineTransformation trans = AffineTransformation.rotationInstance(0.5 * Math.PI, centre.x, centre.y); Polygon comb2 = (Polygon) trans.transform(comb1); MultiPolygon mp = geomFact.createMultiPolygon(new Polygon[] { comb1, comb2 } ); return mp; }
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); }
void checkTransformation(String geomStr) throws IOException, ParseException, NoninvertibleTransformationException { Geometry geom = rdr.read(geomStr); AffineTransformation trans = AffineTransformation .rotationInstance(Math.PI / 2); AffineTransformation inv = trans.getInverse(); Geometry transGeom = (Geometry) geom.copy(); transGeom.apply(trans); // System.out.println(transGeom); transGeom.apply(inv); // check if transformed geometry is equal to original boolean isEqual = geom.equalsExact(transGeom, 0.0005); assertTrue(isEqual); }