Function to drawing Arc in Java

Hello Everybody!!

I have already posted this on the "Jave Programming" forum but this place might be more helpful. I am working on a diagram editor and what I want to do is to allow the user to connect pairs of objects using arcs. ( see this picture http://www.csee.umbc.edu/~squire/images/451-f2.jpg ).

The default drawArc

method in the Graphic class basically requires six parameters: x, y, width, height, startAngle, arcAngle. (EXPLANATION: x - the x coordinate of the upper-left corner of the arc to be drawn, y - the y coordinate of the upper-left corner of the arc to be drawn, width - the width of the arc to be drawn , height - the height of the arc to be drawn , startAngle - the beginning angle, arcAngle - the angular extent of the arc, relative to the start angle ).

Say I want to draw an arc from one point (x1 ,y1) to another point (x2,y2) , how would I determine width, height, startAngle, arcAngle ?

Any help would be greatly appreciated.

[995 byte] By [JImmiThinga] at [2007-10-3 1:27:32]
# 1

>Say I want to draw an arc from one point (x1 ,y1) to another point

> (x2,y2) , how would I determine width, height, startAngle,

> arcAngle ?

It takes 3 non-collinear points to explicitly define a circle. However,

since you only have 2 points then we can assume the circle's diameter

is the distance between the points.

Let's assume the two points have the same y-value. Then, the width

and height are:

x = x1

y = y1

width = Math.abs(x2 - x1)

height = width / 2

beginning angle = 0

arcAngle = Math.PI // this might be -Math.PI ... not sure

Something like that, it shouldn't take too much effort to get it working.

rkippena at 2007-7-14 18:25:07 > top of Java-index,Other Topics,Algorithms...