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 Wed, 07 Dec 2005 18:56:24 GMT
Now this is getting more complicated.  The second time I scale an
element, it moves because the translation value is appended.  This is
tough to explain.  Let's say the center point is 100,100.  If I scale to
2x, I add a translation by (-100 * 1), (-100 * 1).  My new translation
value is (-100, -100).  Now if I scale to 3x, I add a translation by
(-100 * 2), (-100 * 2).  My new translation value is (-300, -300).  This
is wrong.  Why?  Because it doesn't take the first scale into effect!
If I started at a scale factor of 1.0 and scaled directly to 3x, my new
translation value would be (-200, -200).


To summarize, I need to keep translations appended by moving the element
RELATIVE to the previous value and I need to keep translations by
scaling the element ABSOLUTE:


transform=(translate(mx, my) translate(sx, sy) scale(x, y))


Where (mx,my) is the move translation (incremented based on movement),
(sx, sy) is the scale translation (set based on scale factor) and (x, y)
is the scale factor.


So far so good.


What I do in my class that represents elements, however, is store an


String transformValue =

AffineTransform affineTransform =


Then store class variables from the AffineTransform:


Double translateX = new Double(affineTransform.getTranslateX());




The problem is that if I use the above transform attribute, I need to
retrieve TWO translate values from the AffineTransform; one for
movement, one for scaling.  How can I do this?  If I can't, how can I
"parse" an incoming element into the various values?  The reason I
switched to an AffineTransform was to avoid using string parsing to get
the various bits I need.


Michael Bishop




From: Bishop, Michael W. CONTR J9C880
Sent: Wednesday, December 07, 2005 1:15 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Scaling around a center point...


...nevermind, that's not how you get center X/Y.  Now it stays put for
the most part; I'm getting random incorrect translations that I haven't
been able to solve yet.


Michael Bishop



From: Bishop, Michael W. CONTR J9C880
Sent: Wednesday, December 07, 2005 12:44 PM
To: batik-users@xmlgraphics.apache.org
Subject: 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


Michael Bishop

View raw message