Geometry – How to Draw an Arc Between Two Points

geometrytrigonometry

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.

Please help me out.
Thanks in advance.

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

Best Answer

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);
Related Question