[EMAIL PROTECTED] wrote:
If I draw a rectangle in the center of a panel at say (x, y) and then I draw it
again after appying a scale of (sx, sy), how do I get it so that the center of
the rectangle at both scale levels is in the same location on the screen, i.e.
(x, y)? It looks like I need to apply a translate transform (dx, dy) as well
but what would the dx and dy be in this case?
The typical way to change the point around which transforms are applied
(like rotate and scale typically) is to use the following paradigm:
If you want to scale and/or rotate a figure around ox,oy then use:
translate(ox, oy);
// rotate(theta);
// scale(sx, sy);
translate(-ox, -oy);
In your case ox,oy == x,y so just use those coordinates and you should
be fine.
Also, is there some way to determine the *scaled* attributes of the rectangle
after the scale has been applied? Obviously rect.x and rect.width are not
going to change so what I want is the actual location of the rectangle's x and
the actual width of the rectangle as it appears on the screen after the scaling
has been applied.
For a simple transformation like scaling you could just use:
AffineTransform at = new AffineTransform();
at.translate(x, y);
at.scale(sx, sy);
at.translate(-x, -y);
double coords[] = {rx, ry, rx+rw, ry+rh};
at.transform(coords, 0, coords, 0, 2);
scaled rx,ry are in coords[0], coords[1]
scaled rw,rh are calculated as
coords[2] - coords[0], coords[3] - coords[1]
For a more general transform involving flips, rotations, or shears, then
it is not quite so simple as the rectangle will be upside down or
backwards or a general diamond shape...
...jim
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".