UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.awt.geom
Class AffineTransformLib

java.lang.Object
  |
  +--edu.berkeley.guir.lib.awt.geom.AffineTransformLib

public final class AffineTransformLib
extends Object

Miscellaneous affine transform utilities.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.3-1.0.0, Aug 03 1999, JH
               Created class
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib v1.4 release
 

Since:
JDK 1.2.2
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Method Summary
static AffineTransform[] animateLinearly(AffineTransform txFinish, int numFrames)
           
static AffineTransform[] animateSlowInSlowOut(AffineTransform txFinish, int numFrames)
           
static double getRotationFactor(AffineTransform tx)
          Given a transform, figure out its rotation factor.
static double getScaleFactor(AffineTransform tx)
          Given a transform, figure out its scaling factor.
static Point2D getTranslateFactor(AffineTransform tx)
           
static AffineTransform[] interpolate(AffineTransform txStart, AffineTransform txFinish, Interpolation intrp, int numFrames)
           
static void main(String[] argv)
           
static AffineTransform resize(Rectangle2D oldRect, Rectangle2D newRect)
          Calculate the AffineTransform that transforms oldRect into newRect.
static AffineTransform scaleAndCenterAt(double scale, double x, double y, Rectangle2D rect)
          Scale, using the specified point as the new center (absolute coords) after scaling.
static AffineTransform scaleAndKeepConstant(double scale, double x, double y)
          Scale, keeping the specified point constant (ie same absolute coordinates) before and after scaling.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

scaleAndCenterAt

public static AffineTransform scaleAndCenterAt(double scale,
                                               double x,
                                               double y,
                                               Rectangle2D rect)
Scale, using the specified point as the new center (absolute coords) after scaling.
Parameters:
scale - is the scale factor to zoom in to.
x - is where we want to be centered (absolute coords).
y - is where we want to be centered (absolute coords).
rect - is the bounding box of whatever we are zooming, so we know where to center at. For GraphicalObjects, use getBounds2D(COORD_ABS).

scaleAndKeepConstant

public static AffineTransform scaleAndKeepConstant(double scale,
                                                   double x,
                                                   double y)
Scale, keeping the specified point constant (ie same absolute coordinates) before and after scaling.

interpolate

public static AffineTransform[] interpolate(AffineTransform txStart,
                                            AffineTransform txFinish,
                                            Interpolation intrp,
                                            int numFrames)
Parameters:
txStart - is our starting transform, usually identity.
txFinish - is our goal transform.
interpolate - is a function that can interpolate values for us.
numFrames - is the number of intermediate steps.

animateLinearly

public static AffineTransform[] animateLinearly(AffineTransform txFinish,
                                                int numFrames)

animateSlowInSlowOut

public static AffineTransform[] animateSlowInSlowOut(AffineTransform txFinish,
                                                     int numFrames)

resize

public static AffineTransform resize(Rectangle2D oldRect,
                                     Rectangle2D newRect)
Calculate the AffineTransform that transforms oldRect into newRect.
Parameters:
oldRect - is the starting Rectangle.
newRect - is the ending Rectangle.
Returns:
the AffineTransform that transforms oldRect into newRect.

getScaleFactor

public static final double getScaleFactor(AffineTransform tx)
Given a transform, figure out its scaling factor. Only works if the transform does not include any shears. Unfortunately, there doesn't seem to be a SHEAR bit in the AffineTransform, and I don't know if there's an easy way to detect shears.

Because of optimizations, this method is not thread-safe.

Parameters:
tx - is the AffineTransform whose scale factor we want.
Returns:
the scale factor.

getTranslateFactor

public static final Point2D getTranslateFactor(AffineTransform tx)

getRotationFactor

public static final double getRotationFactor(AffineTransform tx)
Given a transform, figure out its rotation factor. Only works if the transform does not include any shears. Unfortunately, there doesn't seem to be a SHEAR bit in the AffineTransform, and I don't know if there's an easy way to detect shears. That's what I get for not having taken an advanced graphics course. My advice to anyone reading this is to take the plunge and take an advanced graphics course.
Parameters:
tx - is the AffineTransform whose rotation factor we want.
Returns:
the rotation factor. If it screws up, returns 0.

main

public static void main(String[] argv)
                 throws Exception

Copyright Information