用2点和圆心画圆弧

发布于 2024-10-02 23:30:32 字数 75 浏览 0 评论 0原文

我有两个圆点和圆心。我想在这些点之间画一条弧线。方法 drawArc 过于简单,不符合我的目的。 有人帮忙吗?

I have two points of circle and center of this circle. I want to draw an arc between these points. Method drawArc is to simple and doesn't fit my purpose.
Anybody help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2024-10-09 23:30:32

您可以使用 Canvas.drawArc,但必须计算它所需的参数:

假设圆的中心是 (x0, y0),弧包含两个点 (x1, y1) 和 (x2, y2)。那么半径为:r=sqrt((x1-x0)(x1-x0) + (y1-y0)(y1-y0))。所以:

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));
canvas.drawArc(x, y, width, height, startAngle, endAngle);

祝你好运!

You can use Canvas.drawArc, but you must compute the arguments it needs:

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));
canvas.drawArc(x, y, width, height, startAngle, endAngle);

Good luck!

冰雪之触 2024-10-09 23:30:32

Graphics.drawArc 需要以下参数:

  • x
  • y
  • width
  • height
  • startAngle
  • arcAngle

给定圆弧起点和终点,可以计算将在其中绘制圆弧的边界框。这为您提供了足够的信息来提供参数:x、y、宽度和高度。

您还没有指定所需的角度,所以我猜您可以任意选择一个。

Graphics.drawArc expects the following parameters:

  • x
  • y
  • width
  • height
  • startAngle
  • arcAngle

Given your arc start and end points it is possible to compute a bounding box where the arc will be drawn. This gives you enough information to provide parameters: x, y, width and height.

You haven't specified the desired angle so I guess you could choose one arbitrarily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文