简体   繁体   中英

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!

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 Circle s 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.

You need more than just that. You need two points, the radius, and the concavity.

Imagine two circles at the two end points, each with a radius of radius. These intersect at two different points (assuming this can be drawn). One of these is your center point, you choose which one by knowing the concavity (ie does the arc go up or down).

You draw your arc using the center point you've chosen and going from one endpoint to the other.

You can find the formula for finding the intersection points of two circles here: http://mathworld.wolfram.com/Circle-CircleIntersection.html

Note that you'd better have exactly two intersection points. If there are zero or infinity, you can't very well draw an arc between them (either your arc won't span, or your arc has zero length).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM