I have the following code:
// get angle of line from 0 - 360
theta = Math.atan2(( point1.getY() - point2.getY()),(point1.getX() - point2.getX()));
theta = 180 - Math.toDegrees(theta);
theta = Math.atan2(( point1.getY() - point2.getY()),(point1.getX() - point2.getX()));
theta = 180 - Math.toDegrees(theta);
GeneralPath arrowhead = new GeneralPath();
double distance = point1.distance(point2);
// create arrowed line general path
arrowhead.moveTo( 0 , 0);
arrowhead.lineTo( (float) distance, 0 );
arrowhead.lineTo( (float) (distance - 8), (float) 6);
arrowhead.lineTo( (float) (distance - 8) , (float) -6);
arrowhead.lineTo( (float) distance , (float) 0 );
AffineTransform at = new AffineTransform();
at.rotate(theta, 0 ,0 );
at.translate(point1.getX() , point1.getY() );
Shape arrow = at.createTransformedShape(arrowhead);
System.out.println(arrow);
g2.draw(arrow);
arrowhead.moveTo( 0 , 0);
arrowhead.lineTo( (float) distance, 0 );
arrowhead.lineTo( (float) (distance - 8), (float) 6);
arrowhead.lineTo( (float) (distance - 8) , (float) -6);
arrowhead.lineTo( (float) distance , (float) 0 );
AffineTransform at = new AffineTransform();
at.rotate(theta, 0 ,0 );
at.translate(point1.getX() , point1.getY() );
Shape arrow = at.createTransformedShape(arrowhead);
System.out.println(arrow);
g2.draw(arrow);
The desired effect is to have an arrowed line drawn from point1 to point2.
So I thought to just draw an abstract line from the point (0,0) with a length of
distance, and to just rotate and translate this shape to be at point 1. However,
I'm not getting the results I'm looking for.
Anyone might know what the problem is? I think it has to do with the
transform. Is that the correct way to set up a translate and rotate
transform?
Thanks,
Walter Shirey
===========================================================================
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".
