Re: rescale using affineTransform, but scaling factor isn't quite honored?



Graham Street wrote:
Hi,  I'm using affineTransform to rescale a polygon to fit in the
screens area.  If the shape is 25% smaller than the drawing area, then
the shape is increased by 25%.     Each side of the shapes length in
inches is initially the same as the length of the side in pixels.

I need the lengths to stay the same when I re-scale the polygon... To
acheive this,  I'm storing the "factor" that I'm supplying to
AffineTransform...     Then, in my getLength() method I divide by this
same number to "reverse" the transform and get the real edge length.
Sometimes it works great (less than half)  but usually it is off.  It's
usually off by less than 1, but occasionally by some huge amount like
30%.

I was thinking this was a casting problem, but it seems to be something
a little trickier.  It seems that the affineTransform scale is actually
not using the same scaling factor all the time..    Does anyone knw
what variables might throw this off and how I might be able to control
it?

Thanks!
Graham Street


Does it appear to change as you run your program? Is it possible that you aren't resetting the transform back to the original when you are done and you are transforming the transform?


public void paint(Graphics g) {
    AffineTransform at = g.getTransform();
    g.scale(x,y);
    g.draw(something);
    g.setTransform(at);

--

Knute Johnson
email s/nospam/knute/
.



Relevant Pages

  • rescale using affineTransform, but scaling factor isnt quite honored?
    ... I'm using affineTransform to rescale a polygon to fit in the ... screens area. ... If the shape is 25% smaller than the drawing area, ... I need the lengths to stay the same when I re-scale the polygon... ...
    (comp.lang.java.gui)
  • Re: Clear image after AffineTransform?
    ... I was reading other threads on AffineTransform. ... that I need to save the original transform. ... > I'm new to Java Graphics. ... > This is what I used to invert the image: ...
    (comp.lang.java.help)
  • auto-scaling polygons using affinetransform but maintaining unscaled lenghts
    ... apply that scaling factor using an AffineTransform ... change the individial edges in my shape to reflect the transform by ... But my real challenge is maintaining the original lengths for display ... calling inverseTransform, hoping to arrive back at my original points ...
    (comp.lang.java.gui)