## Examples of AffineTransform

• ae.java.awt.geom.AffineTransform
The AffineTransform class represents a 2D affine transform that performs a linear mapping from 2D coordinates to other 2D coordinates that preserves the "straightness" and "parallelness" of lines. Affine transformations can be constructed using sequences of translations, scales, flips, rotations, and shears.

Such a coordinate transformation can be represented by a 3 row by 3 column matrix with an implied last row of [ 0 0 1 ]. This matrix transforms source coordinates {@code (x,y)} intodestination coordinates {@code (x',y')} by consideringthem to be a column vector and multiplying the coordinate vector by the matrix according to the following process:

[ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ] [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ] [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ]

#### Handling 90-Degree Rotations

In some variations of the rotate methods in the AffineTransform class, a double-precision argument specifies the angle of rotation in radians. These methods have special handling for rotations of approximately 90 degrees (including multiples such as 180, 270, and 360 degrees), so that the common case of quadrant rotation is handled more efficiently. This special handling can cause angles very close to multiples of 90 degrees to be treated as if they were exact multiples of 90 degrees. For small multiples of 90 degrees the range of angles treated as a quadrant rotation is approximately 0.00000121 degrees wide. This section explains why such special care is needed and how it is implemented.

Since 90 degrees is represented as PI/2 in radians, and since PI is a transcendental (and therefore irrational) number, it is not possible to exactly represent a multiple of 90 degrees as an exact double precision value measured in radians. As a result it is theoretically impossible to describe quadrant rotations (90, 180, 270 or 360 degrees) using these values. Double precision floating point values can get very close to non-zero multiples of PI/2 but never close enough for the sine or cosine to be exactly 0.0, 1.0 or -1.0. The implementations of Math.sin() and Math.cos() correspondingly never return 0.0 for any case other than Math.sin(0.0). These same implementations do, however, return exactly 1.0 and -1.0 for some range of numbers around each multiple of 90 degrees since the correct answer is so close to 1.0 or -1.0 that the double precision significand cannot represent the difference as accurately as it can for numbers that are near 0.0.

The net result of these issues is that if the Math.sin() and Math.cos() methods are used to directly generate the values for the matrix modifications during these radian-based rotation operations then the resulting transform is never strictly classifiable as a quadrant rotation even for a simple case like rotate(Math.PI/2.0), due to minor variations in the matrix caused by the non-0.0 values obtained for the sine and cosine. If these transforms are not classified as quadrant rotations then subsequent code which attempts to optimize further operations based upon the type of the transform will be relegated to its most general implementation.

Because quadrant rotations are fairly common, this class should handle these cases reasonably quickly, both in applying the rotations to the transform and in applying the resulting transform to the coordinates. To facilitate this optimal handling, the methods which take an angle of rotation measured in radians attempt to detect angles that are intended to be quadrant rotations and treat them as such. These methods therefore treat an angle theta as a quadrant rotation if either Math.sin(theta) or Math.cos(theta) returns exactly 1.0 or -1.0. As a rule of thumb, this property holds true for a range of approximately 0.0000000211 radians (or 0.00000121 degrees) around small multiples of Math.PI/2.0. @author Jim Graham @since 1.2

• chunmap.model.crs.transf.AffineTransform
仿射变换 @author chunquedong
• com.itextpdf.awt.geom.AffineTransform
• com.jgraph.gaeawt.java.awt.geom.AffineTransform
• com.sk89q.worldedit.math.transform.AffineTransform

• java.awt.geom.AffineTransform
The AffineTransform class represents a 2D affine transform that performs a linear mapping from 2D coordinates to other 2D coordinates that preserves the "straightness" and "parallelness" of lines. Affine transformations can be constructed using sequences of translations, scales, flips, rotations, and shears.

Such a coordinate transformation can be represented by a 3 row by 3 column matrix with an implied last row of [ 0 0 1 ]. This matrix transforms source coordinates {@code (x,y)} intodestination coordinates {@code (x',y')} by consideringthem to be a column vector and multiplying the coordinate vector by the matrix according to the following process:

[ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ] [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ] [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ]

#### Handling 90-Degree Rotations

In some variations of the rotate methods in the AffineTransform class, a double-precision argument specifies the angle of rotation in radians. These methods have special handling for rotations of approximately 90 degrees (including multiples such as 180, 270, and 360 degrees), so that the common case of quadrant rotation is handled more efficiently. This special handling can cause angles very close to multiples of 90 degrees to be treated as if they were exact multiples of 90 degrees. For small multiples of 90 degrees the range of angles treated as a quadrant rotation is approximately 0.00000121 degrees wide. This section explains why such special care is needed and how it is implemented.

Since 90 degrees is represented as PI/2 in radians, and since PI is a transcendental (and therefore irrational) number, it is not possible to exactly represent a multiple of 90 degrees as an exact double precision value measured in radians. As a result it is theoretically impossible to describe quadrant rotations (90, 180, 270 or 360 degrees) using these values. Double precision floating point values can get very close to non-zero multiples of PI/2 but never close enough for the sine or cosine to be exactly 0.0, 1.0 or -1.0. The implementations of Math.sin() and Math.cos() correspondingly never return 0.0 for any case other than Math.sin(0.0). These same implementations do, however, return exactly 1.0 and -1.0 for some range of numbers around each multiple of 90 degrees since the correct answer is so close to 1.0 or -1.0 that the double precision significand cannot represent the difference as accurately as it can for numbers that are near 0.0.

The net result of these issues is that if the Math.sin() and Math.cos() methods are used to directly generate the values for the matrix modifications during these radian-based rotation operations then the resulting transform is never strictly classifiable as a quadrant rotation even for a simple case like rotate(Math.PI/2.0), due to minor variations in the matrix caused by the non-0.0 values obtained for the sine and cosine. If these transforms are not classified as quadrant rotations then subsequent code which attempts to optimize further operations based upon the type of the transform will be relegated to its most general implementation.

Because quadrant rotations are fairly common, this class should handle these cases reasonably quickly, both in applying the rotations to the transform and in applying the resulting transform to the coordinates. To facilitate this optimal handling, the methods which take an angle of rotation measured in radians attempt to detect angles that are intended to be quadrant rotations and treat them as such. These methods therefore treat an angle theta as a quadrant rotation if either Math.sin(theta) or Math.cos(theta) returns exactly 1.0 or -1.0. As a rule of thumb, this property holds true for a range of approximately 0.0000000211 radians (or 0.00000121 degrees) around small multiples of Math.PI/2.0. @version 1.77, 03/09/06 @author Jim Graham @since 1.2

• pythagoras.f.AffineTransform
Implements an affine (3x2 matrix) transform. The transformation matrix has the form:
{@code [ m00, m10, tx ] [ m01, m11, ty ] [   0,   0,  1 ]}

### Examples of ae.java.awt.geom.AffineTransform

 389390391392393394395 focus,              fractions,              colors,              cycleMethod,              ColorSpaceType.SRGB,              new AffineTransform());     }
View Full Code Here

### Examples of chunmap.model.crs.transf.AffineTransform

 6667686970717273747576 private Geometry getGeometry(CPoint p1, CPoint p2) {     Vector v1 = new Vector(p1, p2);     Vector v2 = new Vector(new Coordinate2D(0, 0), new Coordinate2D(0, 1));     double angle = v1.computeAngle(v2);     AffineTransform transf = AffineTransform.rotate(0, 0, angle + Math.PI         / 2d);     AffineTransform transf2 = transf.accumulate(AffineTransform.pan(p2         .getX(), p2.getY()));     return geometry.transform(transf2);   }
View Full Code Here

 320321322323324325326327328 m12 = py * (1.0 - m00) - px * m10;         type = TYPE_UNKNOWN;     }     public static AffineTransform getTranslateInstance(double mx, double my) {         AffineTransform t = new AffineTransform();         t.setToTranslation(mx, my);         return t;     }
View Full Code Here

### Examples of com.itextpdf.awt.geom.AffineTransform

 3482348334843485348634873488 * @deprecated use com.itextpdf.text.geom.AffineTransform as parameter      */     public void addImage(final Image image, final java.awt.geom.AffineTransform transform) throws DocumentException {       double matrix[] = new double[6];       transform.getMatrix(matrix);       addImage(image, new AffineTransform(matrix));     }
View Full Code Here

### Examples of com.jgraph.gaeawt.java.awt.geom.AffineTransform

 342343344345346347348349350351352353354355356357358359360361362363 Rectangle normDstBounds = new Rectangle(0, 0, dstBounds.width,         dstBounds.height);     Rectangle bounds = getBounds2D(src).getBounds().intersection(         normDstBounds);     AffineTransform inv = null;     try     {       inv = at.createInverse();     }     catch (NoninvertibleTransformException e)     {       return -1;     }     double[] m = new double[6];     inv.getMatrix(m);     int minSrcX = srcBounds.x;     int minSrcY = srcBounds.y;     int maxSrcX = srcBounds.x + srcBounds.width;     int maxSrcY = srcBounds.y + srcBounds.height;
View Full Code Here

### Examples of com.sk89q.worldedit.math.transform.AffineTransform

 11631164116511661167116811691170117111721173 Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);         Vector to = region.getMinimumPoint();         ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);         copy.setRepetitions(count);         copy.setTransform(new AffineTransform().translate(dir.multiply(size)));         if (!copyAir) {             copy.setSourceMask(new ExistingBlockMask(this));         }         Operations.completeLegacy(copy);         return copy.getAffected();
View Full Code Here

### Examples of java.awt.geom.AffineTransform

 149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 int width = old_img.getWidth();     int height = old_img.getHeight();     BufferedImage new_img = new BufferedImage(height,width,BufferedImage.TYPE_INT_RGB);                Graphics2D g2d =new_img.createGraphics();                 AffineTransform origXform = g2d.getTransform();         AffineTransform newXform = (AffineTransform)(origXform.clone());         // center of rotation is center of the panel     double radian = 0;         double xRot = 0;         double yRot = 0;     switch(orient){     case 3:       radian = 180.0;       xRot = width/2.0;       yRot = height/2.0;     case 6:       radian = 90.0;           xRot = height/2.0;           yRot = xRot;       break;     case 8:       radian = 270.0;           xRot = width/2.0;           yRot = xRot;           break;         default:           return false;     }         newXform.rotate(Math.toRadians(radian), xRot, yRot);         g2d.setTransform(newXform);           // draw image centered in panel         g2d.drawImage(old_img, 0, 0, null);         // Reset to Original
View Full Code Here

### Examples of java.awt.geom.AffineTransform

 565758596061626364656667686970 int height = old_img.getHeight();         BufferedImage new_img = new BufferedImage(height,width,BufferedImage.TYPE_INT_BGR);                Graphics2D g2d =new_img.createGraphics();                 AffineTransform origXform = g2d.getTransform();         AffineTransform newXform = (AffineTransform)(origXform.clone());         // center of rotation is center of the panel         double xRot = width/2.0;         newXform.rotate(Math.toRadians(270.0), xRot, xRot);         g2d.setTransform(newXform);           // draw image centered in panel         g2d.drawImage(old_img, 0, 0, null);         // Reset to Original
View Full Code Here

### Examples of java.awt.geom.AffineTransform

 461462463464465466467468469470471 g2d.setRenderingHint(RenderingHints.KEY_RENDERING,             smooth ? RenderingHints.VALUE_RENDER_QUALITY :                 RenderingHints.VALUE_RENDER_SPEED         );         AffineTransform at = AffineTransform.getScaleInstance(             (double) w / width,             (double) h / height         );         g2d.drawImage(image, at, null);         g2d.dispose();
View Full Code Here

### Examples of java.awt.geom.AffineTransform

 151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 if (log.isDebugEnabled()) {             log.debug("Generating SVG at " + deviceResolution + "dpi.");         }         final float uaResolution = userAgent.getSourceResolution();         SVGUserAgent ua = new SVGUserAgent(userAgent, new AffineTransform());         //Scale for higher resolution on-the-fly images from Batik         double s = uaResolution / deviceResolution;         AffineTransform resolutionScaling = new AffineTransform();         resolutionScaling.scale(s, s);         //Controls whether text painted by Batik is generated using text or path operations         boolean strokeText = false;         Configuration cfg = pdfInfo.cfg;         if (cfg != null) {             strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText);         }         BridgeContext ctx = new PDFBridgeContext(ua,                 (strokeText ? null : pdfInfo.fi),                 userAgent.getFactory().getImageManager(),                 userAgent.getImageSessionContext(),                 new AffineTransform());         //Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)         //to it.         Document clonedDoc = BatikUtil.cloneSVGDocument(doc);         GraphicsNode root;         try {             GVTBuilder builder = new GVTBuilder();             root = builder.build(ctx, clonedDoc);         } catch (Exception e) {             SVGEventProducer eventProducer = SVGEventProducer.Provider.get(                     context.getUserAgent().getEventBroadcaster());             eventProducer.svgNotBuilt(this, e, getDocumentURI(doc));             return;         }         // get the 'width' and 'height' attributes of the SVG document         float w = (float)ctx.getDocumentSize().getWidth() * 1000f;         float h = (float)ctx.getDocumentSize().getHeight() * 1000f;         float sx = pdfInfo.width / w;         float sy = pdfInfo.height / h;         //Scaling and translation for the bounding box of the image         AffineTransform scaling = new AffineTransform(                 sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f);         //Transformation matrix that establishes the local coordinate system for the SVG graphic         //in relation to the current coordinate system         AffineTransform imageTransform = new AffineTransform();         imageTransform.concatenate(scaling);         imageTransform.concatenate(resolutionScaling);         /*          * Clip to the svg area.          * Note: To have the svg overlay (under) a text area then use          * an fo:block-container
View Full Code Here