## 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 java.awt.geom.AffineTransform

 `9293949596979899100101102` ```     */     public BasicIconPart(Shape shape, AffineTransform transform, DrawingAttributes da) {         geometry = shape;         if (transform == null) {             transform = new AffineTransform();         }         baseTransform = transform;         setRenderingAttributes(da);     } ```
View Full Code Here

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

 `131132133134135136137138139140141142143` ```     *        drawing attributes if they want/should. May be null.      */     public void render(Graphics g, int width, int height,                        DrawingAttributes appDA) {         AffineTransform transform = AffineTransform.getScaleInstance((double) width / 100,                 (double) height / 100);         transform.concatenate(baseTransform);         // Handle clip area in Graphics, first         Shape clip = getClip();         if (clip != null) {             g.setClip(new GeneralPath(clip).createTransformedShape(transform)); ```
View Full Code Here

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

 `1448144914501451145214531454` ```   * @see Graphics2D#getFontRenderContext()    */   public FontRenderContext getFontRenderContext() {       boolean antialias = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));       boolean fractions = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));       return new FontRenderContext(new AffineTransform(), antialias, fractions);   } ```
View Full Code Here

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

 `1493149414951496149714981499` ```   /**    * @see Graphics2D#getTransform()    */   public AffineTransform getTransform() {       return new AffineTransform(oTransform);   } ```
View Full Code Here

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

 `1543154415451546154715481549155015511552155315541555155615571558155915601561` ```    paint = Color.black;     // possible: if parent.color is not black, then force black?     // must check to see what AWT does?         // Original User Space Transform (identity)     oTransform = new AffineTransform();         // Transform from Java Space to PDF Space   pTransform = new AffineTransform();   pTransform.translate(0, pf.getHeight());   pTransform.scale(1d, -1d);   // Combined Transform User->Java->PDF   transform = new AffineTransform(oTransform);   transform.concatenate(pTransform);     // Set the line width     setStroke(DEF_STROKE);   } ```
View Full Code Here

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

 `1990199119921993199419951996199719981999` ```   */   public void setTransform(AffineTransform t) {     // Save copy of original transform.       oTransform = t;       // Working copy of transform       transform = new AffineTransform(t);       // Concatenate Java Space to PDF Space transform       transform.concatenate(pTransform);       this.stroke = transformStroke(originalStroke);   } ```
View Full Code Here

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

 `377378379380381382383384385386387388389390` ```        private void rotate(int degrees) {         img = picture.getImage();                 BufferedImage src = Utilities.toBufferedImage(new DcImageIcon(img));         AffineTransform at = new AffineTransform();                 at.rotate(Math.toRadians(degrees), src.getWidth() / 2.0, src.getHeight() / 2.0);         AffineTransform translationTransform = findTranslation (at, src);         at.preConcatenate(translationTransform);         BufferedImage destinationBI = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC).filter(src, null);         picture = new DcImageIcon(Utilities.getBytes(new DcImageIcon(destinationBI)));         initialize(); ```
View Full Code Here

### Examples of pythagoras.f.AffineTransform

 `221222223224225226227` ```    }     /** Utility method for capture. */     protected static AffineTransform toAffine (Transform t) {         if (t instanceof AffineTransform) return (AffineTransform)t;         else return new AffineTransform(t.scaleX(), t.scaleY(), t.rotation(), t.tx(), t.ty());     } ```
View Full Code Here