Search code examples
javagraphics2d

Draw an arc based on 2 Points and radius


I'm trying to draw an Arc2D object inside a panel. however I'm not sure how to calculate it. What I have given is starting Point2D and an end Point2D and a radius. The problem is that when the radius changes, the startAngle and AngleExtent parameters are different every time. another problem is that since the radius changes, the center of the 'to-be' circle containing the arc is in a different point every time, another parameter which changes based on input, so I can't use (or don't know how) to use setCenter() method.

Any help is appreciated!


Solution

  • Two points and a radius define two arcs (in 2D). You can find their center points by calculating the intersection (java.awt.geom.Area.intersects) of the two Circles of radius r centered at your two points. The center point of the arcs' circles will be the points on the perimeter of that area halfway between your two initial points.