You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2005/12/07 18:44:21 UTC

Scaling around a center point...

More transform issues!  As you may recall, I add a translate value to
move objects around the canvas.  Now I'm working on scaling and I like
the scale to be uniform around the center of element.  I get the center
point by asking the Element for its bounding box:

 

centerX = boundingBox.getWidth() - boundingBox.getX();

centerY = boundingBox.getHeight() - boundingBox.getY();

 

In the SVG Essentials book I have, it says to scale around a center
point, the translate should be set to:

 

translate(-centerX * (factor - 1), -centerY * (factor - 1))

 

Instead of setting the above, I ADD the above to the existing translate
if one exists.  However, when I scale, the element stays nowhere near
the center point.  I tried simply SETTING the translate values, losing
the previous ones and it's still wrong.  Is there a better technique for
scaling around the center of an element, or is my math just wrong
somewhere?

 

Michael Bishop