xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: Scaling around a center point...
Date Thu, 08 Dec 2005 18:30:24 GMT
I think it is.  I'll smile, nod, pretend I understand how it works and
check it out.  It looks like I'll need to convert radians to degrees
because I think the rotate parameter wants degrees, but I'm sure there's
an easy way to do that.  Thanks a bunch, I'll give this a try.

Michael Bishop

-----Original Message-----
From: Archie Cobbs [mailto:archie@dellroad.org] 
Sent: Thursday, December 08, 2005 1:21 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: Scaling around a center point...

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

---------------------------------------------------------------------
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