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 19:28:25 GMT
OK, my transform attribute is getting totally hosed now.  I'm using
this:

transform="translate(x, y) scale(sx, sy) rotate(t, cx, cy)"

This is to ensure I can rotate around a center point.  When I rotate it
once, it works fine.  When I reselect the element later (thus parsing
the AffineTransform I posted before), everything goes haywire.  I have
values in the translate that weren't there.  I have scale values for
scaling I didn't perform.  Only thing that looks right is the rotate,
but everything else is off the canvas.

Michael Bishop

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Thursday, December 08, 2005 1:30 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Scaling around a center point...

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

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