Draw an arc based on 2 Points and radius

自闭症网瘾萝莉.ら 提交于 2019-12-24 20:21:07

问题


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!


回答1:


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.




回答2:


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 (i.e. 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).



来源:https://stackoverflow.com/questions/11387493/draw-an-arc-based-on-2-points-and-radius

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!