|
Hello, I have a question involving Graphics2D and the
AffineTransform:
Basically what I want to be able to do is this:
draw a circle on
top of a scaled and rotated image, such that no matter what the scale, shear, rotation is, the circle will remain a consistent size and shape. AND the center of the circle needs to be positioned with reference to the scaled image's coordinate system. Here's some of the details:
I have an image which is originally about 512
pixels by 26 pixels.
(A coronal projection based on 26 CAT scan slices.) This gets scaled up to about 512 by 400 pixels in
order to properly
scale anatomical features. I want to draw several dots on top of the image to
mark certain
reference points. I do this by filling an Ellipse2D. After the original scaling, the user can zoom, pan,
and rotate the image.
During these operations I want the dots to remain constant in size and shape. Because of the original scaling of the image in the
y direction,
I construct my Ellipse2D something like this: Ellipse2D.Double circ = new
Ellipse2D.Double(0d, 0d, 4d, 4d/yScale);
This looks great until the image is rotated. As I rotate from 0 to 90 degrees clockwise, the dots first get smaller, then at 90 degrees they appear as thin lines. I've included my drawing code below, any
suggestions would be very much
appreciated. Thank you,
Ted Hill
========================================================================
private void drawDots(Graphics2D
g2, List pointList)
{ double xScale = getScaleX(g2); double
yScale = getScaleY(g2);
Ellipse2D.Double circ = new Ellipse2D.Double(0d, 0d, 4d/xScale,
4d/yScale);
Point2D
pt = null;
for(int
i = 0; i < pointList.size( );
i++)
{ pt = (Point2D)pointList.get(i); circ.x
= pt.getX(
);
circ.y = pt.getY( );
g2.fill(circ);
} } private double getScaleY(Graphics2D g2) { AffineTransform at = g2.getTransform( ); final
double yScale = at.getScaleY( );
final
double yShear = at.getShearY( );
return
Math.sqrt((yScale * yScale) + (yShear * yShear));
} private double
getScaleX(Graphics2D g2)
{ AffineTransform at = g2.getTransform( ); final
double xScale = at.getScaleX( );
final
double xShear = at.getShearX( );
return
Math.sqrt((xScale * xScale) + (xShear * xShear));
} |
- Re: [JAVA2D] AffineTransform question Jim Bucher
- Re: [JAVA2D] AffineTransform question Ted Hill
- Re: [JAVA2D] AffineTransform question Jim Bucher
- Re: [JAVA2D] AffineTransform question Ted Hill
