I would say that there are two approaches:

1) Use AffineTransform.transform() to map the points that define the
line to "panel space" and then draw the line using the original
transform that was passed in to your paintComponent() method.

2) If you only want a line that is one pixel wide, you can set the width
of the line to be very thin, which I think will force it to be at least
one pixel wide. This way you can draw the line with points defined in
your transformed space instead of in panel space.

Here is a method that will return a thin line width based on the current
scaling of a transform.

/**
 * Return the scale factor for the stroke width based on the
AffineTransform
 * For example if the desired stroke width is one
 * pixel, but we are drawing in a transformed space, a BasicStroke of
 * width one, might be rendered as 4 pixels, in that case, return .25
 * so that will only use one pixel for rendering in the transformed
space.
 *
 * @param at   the AffineTransform
 */
public static double getStrokeWidthScale(AffineTransform at)
{
    final double xScale = at.getScaleX( );
    final double yScale = at.getScaleY( );

    final double xShear = at.getShearX( );
    final double yShear = at.getShearY( );

    final double xVal = Math.sqrt((xScale * xScale) + (xShear *
xShear));
    final double yVal = Math.sqrt((yScale * yScale) + (yShear *
yShear));

    double scale  = Math.max(xVal, yVal);

    return scale;
}

Ted Hill

> -----Original Message-----
> From: Mark Smiley [mailto:[EMAIL PROTECTED]]
> Sent: Monday, January 20, 2003 10:22 AM
> To: [EMAIL PROTECTED]
> Subject: [JAVA2D] Line thickness varies by slope when using
GeneralPath
> with AffineTransform
> 
> If I set an AffineTransform on a Graphics2D with a scale along one
axis
> that is drastically different from the other axis (e.g. x-axis has
range
> 0-10, and y-axis has range 0-1000), when I render a GeneralPath, the
> thickness of the line segments varies depending on the slope of the
line.
> E.g. a line segment from (0,0) to (1, 1000) will be much thicker than
one
> from (1,100) to (2, 100).
> 
> Is there some way to normalize the line thickness, while still using
the
> affine transform on Graphics2D?  Or is there a better approach?
> 
> Thanks.
> 
>
========================================================================
==
> =
> 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".

==========================================================================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".

Reply via email to