# Drawing an arc between two points

I was writing a java program to draw an arc. Arc2D.Double(int x,int y,int width,int height,int startAngle,int arcAngle,int type);

Since, I'm not familiar with the mathematics behind drawing arc, I'm facing the problem. Basically, what I want to is...I want to draw an arc between two points A and B. I want to draw an arc between the two lines depicting the angle between them. Some body please help me in calculating the startAngle and arcAngle.

Well, I found the answer to my scenario here...

Since, I don't have enough reputation to answer I'm writing it here....

Lets say that the center of the circle is (x0, y0) and that the arc contains your two points (x1, y1) and (x2, y2). Then the radius is: r=sqrt((x1-x0)(x1-x0) + (y1-y0)(y1-y0)). So:

int r = (int)Math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
int x = x0-r;
int y = y0-r;
int width = 2*r;
int height = 2*r;
int startAngle = (int) (180/Math.PI*atan2(y1-y0, x1-x0));
int endAngle = (int) (180/Math.PI*atan2(y2-y0, x2-x0));
graphics.drawArc(x, y, width, height, startAngle, endAngle);


Thanks & Regards

-
You mention $x$ and $y$ coordinates as well as a width, a height, an startAngle an arcAngle and a type as input. What do they represent? And what is the angle between two points $A$ and $B$? Do you mean “with respect to the origin”, i.e. you draw a line through $A$ and the origin $(0,0)$ and a line through $B$ and the origin and that’s the angle? –  k.stm May 13 '13 at 10:44
I want to draw an arc at the corner of two intersecting lines.Type represents CHORD,OPEN,PIE types.x and y represents the top left corner of the bounding rectangle of the arc shape. –  pinkpanther May 13 '13 at 10:56
Intersection between two lines (corner) is the origin.... –  pinkpanther May 13 '13 at 11:07
Maybe this can help you. In your case, $θ = \arccos \big(\tfrac{a}{\sqrt{a^2 + b^2}}\big)$ gives you the angle $θ$ of the point $(a,b)$ to the (right ray of the) horizontal axis. –  k.stm May 13 '13 at 11:19
@K.Stm Thanks for your help.Well, I found the answer to my scenario here stackoverflow.com/questions/4196749/… –  pinkpanther May 13 '13 at 12:44

Well, I can answer it now I found the answer...here

Lets say that the center of the circle is (x0, y0) and that the arc contains your two points (x1, y1) and (x2, y2). Then the radius is: r=sqrt((x1-x0)(x1-x0) + (y1-y0)(y1-y0)). So:

int r = (int)Math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
int x = x0-r;
int y = y0-r;
int width = 2*r;
int height = 2*r;
int startAngle = (int) (180/Math.PI*atan2(y1-y0, x1-x0));
int endAngle = (int) (180/Math.PI*atan2(y2-y0, x2-x0));
graphics.drawArc(x, y, width, height, startAngle, endAngle);

-