xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Archie Cobbs <arc...@dellroad.org>
Subject Re: Scaling around a center point...
Date Thu, 08 Dec 2005 18:20:40 GMT
Bishop, Michael W. CONTR J9C880 wrote:
> transform="translate(x, y) scale(x, y) rotate(t)"
> 
> Is there a way to get the value of t?

Here's a method I wrote to do this. Not sure if it's what
you need but perhaps it could be a start (no guarantees :-).

     /**
      * Compute the rotation angle of an affine transformation.
      * Counter-clockwise rotation is considered positive.
      *
      * @return rotation angle in radians (beween -pi and pi),
      *  or NaN if the transformation is bogus.
      */
     public static double getRotationAngle(AffineTransform transform) {

         // Eliminate any post-translation
         transform = (AffineTransform)transform.clone();
         transform.preConcatenate(AffineTransform.getTranslateInstance(
           -transform.getTranslateX(), -transform.getTranslateY()));

         // Apply transformation to a vector
         Point2D v1 = new Point2D.Double(1, 0);
         Point2D v2 = transform.transform(v1, null);

         // Compute dot product
         double dotProduct = v1.getX() * v2.getX() + v1.getY() * v2.getY();

         // Compute positive angle
         double angle = Math.acos(dotProduct
           / (v1.distance(0, 0) * v2.distance(0, 0)));

         // Negate angle if rotation direction is clockwise
         if (v2.getY() < 0)
             angle = -angle;

         // Done
         return angle;
     }

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

-- 

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message