简体   繁体   English

根据2个点和半径绘制圆弧

[英]Draw an arc based on 2 Points and radius

I'm trying to draw an Arc2D object inside a panel. 我正在尝试在面板内绘制一个Arc2D对象。 however I'm not sure how to calculate it. 但是我不确定如何计算。 What I have given is starting Point2D and an end Point2D and a radius. 我给出的是起点Point2D和终点Point2D和半径。 The problem is that when the radius changes, the startAngle and AngleExtent parameters are different every time. 问题在于,当半径改变时,startAngle和AngleExtent参数每次都不同。 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. 另一个问题是,由于半径发生变化,因此每次包含圆弧的“拟”圆的中心都在不同的点,另一个参数根据输入而变化,所以我无法使用(或不知道如何)使用setCenter()方法。

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. 您可以通过计算以两个点为中心的半径r的两个Circle的交点(java.awt.geom.Area.intersects)来找到它们的中心点。 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 您可以在此处找到用于找到两个圆的交点的公式: 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). 如果为零或无穷大,则您将无法在它们之间绘制圆弧(您的圆弧无法跨越,或者您的圆弧长度为零)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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