From: Jody G. <jod...@gm...> - 2010-08-19 04:01:05
|
You may wish to add some of that to the wiki page :-) I will note if you don't like math, you can just use the methods of the AffineTransform object. Jody On Thu, Aug 19, 2010 at 1:01 PM, <chr...@nv...> wrote: > > Some mathematical basics here. > An affine transform is a powerful mechanism to transform coordinates. > To get the new coordinates x' and y', the following calculation is done. > > [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] > [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] > [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] > > A simple example: > if you want to shift a point 5 units on the x axis and -7 units at the > y axis, the following matrix is needed > > [ 1 0 5 ] > [ 0 1 -7 ] > [ 0 0 1 ] > > Of course, you can say this is easy, x'=x+5 and y'=y-7 would do the same. > > Another one, lets do some scaling, say factor 3 > > [ 3 0 0 ] > [ 0 3 0 ] > [ 0 0 1 ] > > This is easy too, x'=x*3 and y'=y*3 would the job. > > The power of affine transforms is that you can combine multiple > matrices into a single one, doing a set of individual transformations > within one step. There is a java method "concatenate(AffineTransform)" > for the AffineTransform class. But be careful, given 3 transformatons > A,B,C and you want to combine them in this order, you have to go from > right to left. > C concatenate B concatenate A will give you the expected result. > > A mapping from world coordinates to pixel coordinates needs some > operations but can be done within one affine transformation. > > The second powerful feature is that you can create an inverse > transform (Method createInverse), which will do the mapping in the > other direction out of the box. > > Believe me, if you are used to use AffineTransform objects, you will > use them forever. > > Hope this helps > Cheers > Christian > > > > > > > > > > > > > > > > > Quoting andrea antonello <and...@gm...>: > >> Hi Tommaso, >> the easiest way to do a rotation for example is: >> >> Coordinate ancorPoint = ...; >> AffineTransform affineTransform = >> AffineTransform.getRotateInstance(angleRad, ancorPoint.x, >> ancorPoint.y); >> MathTransform mathTransform = new AffineTransform2D(affineTransform); >> >> Point point = ...point to rotate; >> Geometry rotatedPoint = JTS.transform(point, mathTransform); >> >> Where point can be any geometry. >> >> Does that help? >> >> Ciao >> Andrea >> >> >> On Wed, Aug 18, 2010 at 11:26 PM, tommaso <tom...@go...> wrote: >>> Hallo List, >>> >>> I would like to perform some geometry transformations on polygons, i.e >>> rotate about a point, scale and translate. >>> >>> So I create the polygon: >>> >>> import com.vividsolutions.jts.geom.Coordinate >>> import org.geotools.geometry.jts.JTSFactoryFinder >>> import com.vividsolutions.jts.geom.GeometryFactory >>> import com.vividsolutions.jts.geom.LinearRing >>> import com.vividsolutions.jts.geom.Polygon >>> >>> GeometryFactory geometryFactory = >>> JTSFactoryFinder.getGeometryFactory( null ); >>> >>> Coordinate[] coords = [new Coordinate(0, 0), new Coordinate(2, 0), >>> new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(0, 0)] >>> LinearRing ring = new LinearRing(coords, geometryFactory) >>> Polygon polygon = geometryFactory.createPolygon(ring) >>> >>> I guess I have to use AffineTransform >>> (com.vividsolutions.jts.geom.util.AffineTransformation ?) but I don't know >>> exactly how. >>> A code example or a link to a tutorial were very appreciated. >>> >>> Cheers, >>> Tom >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by >>> >>> Make an app they can't live without >>> Enter the BlackBerry Developer Challenge >>> http://p.sf.net/sfu/RIM-dev2dev >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geo...@li... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >>> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by >> >> Make an app they can't live without >> Enter the BlackBerry Developer Challenge >> http://p.sf.net/sfu/RIM-dev2dev >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geo...@li... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |