/** * Creates an AffineTransformation defined by a set of control vectors. * Between one and three vectors must be supplied. * * @param src * the source points of the vectors * @param dest * the destination points of the vectors * @return the computed transformation * @throws IllegalArgumentException * if the control vector arrays are too short, long or of different * lengths */ public static AffineTransformation createFromControlVectors(Coordinate[] src, Coordinate[] dest) { if (src.length != dest.length) throw new IllegalArgumentException( "Src and Dest arrays are not the same length"); if (src.length <= 0) throw new IllegalArgumentException("Too few control points"); if (src.length > 3) throw new IllegalArgumentException("Too many control points"); if (src.length == 1) return createFromControlVectors(src[0], dest[0]); if (src.length == 2) return createFromControlVectors(src[0], src[1], dest[0], dest[1]); return createFromControlVectors(src[0], src[1], src[2], dest[0], dest[1], dest[2]); }
@Metadata(description="Transforms a geometry using one to three control vectors") public static Geometry transformByVectors(Geometry g, Geometry control) { int nControl = control.getNumGeometries(); Coordinate src[] = new Coordinate[nControl]; Coordinate dest[] = new Coordinate[nControl]; for (int i = 0; i < nControl; i++) { Geometry contComp = control.getGeometryN(i); Coordinate[] pts = contComp.getCoordinates(); src[i] = pts[0]; dest[i] = pts[1]; } AffineTransformation trans = AffineTransformationFactory.createFromControlVectors(src, dest); System.out.println(trans); return trans.transform(g); }
void run(double p0x, double p0y, double pp0x, double pp0y ) { Coordinate p0 = new Coordinate(p0x, p0y); Coordinate pp0 = new Coordinate(pp0x, pp0y); AffineTransformation trans = AffineTransformationFactory.createFromControlVectors( p0, pp0); Coordinate dest = new Coordinate(); assertEqualPoint(pp0, trans.transform(p0, dest)); }
void run(double p0x, double p0y, double p1x, double p1y, double pp0x, double pp0y, double pp1x, double pp1y ) { Coordinate p0 = new Coordinate(p0x, p0y); Coordinate p1 = new Coordinate(p1x, p1y); Coordinate pp0 = new Coordinate(pp0x, pp0y); Coordinate pp1 = new Coordinate(pp1x, pp1y); AffineTransformation trans = AffineTransformationFactory.createFromControlVectors( p0, p1, pp0, pp1); Coordinate dest = new Coordinate(); assertEqualPoint(pp0, trans.transform(p0, dest)); assertEqualPoint(pp1, trans.transform(p1, dest)); }