简体   繁体   English

用2点和圆心绘制圆弧

[英]Draw arc with 2 points and center of the circle

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. 方法drawArc很简单,不符合我的目的。 Anybody help? 有人帮忙吗?

You can use Canvas.drawArc, but you must compute the arguments it needs: 您可以使用Canvas.drawArc,但必须计算它需要的参数:

Lets say that the center of the circle is (x0, y0) and that the arc contains your two points (x1, y1) and (x2, y2). 让我们说圆的中心是(x0,y0)并且弧包含你的两个点(x1,y1)和(x2,y2)。 Then the radius is: r=sqrt((x1-x0) (x1-x0) + (y1-y0) (y1-y0)). 然后半径是: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! 祝好运!

Graphics.drawArc expects the following parameters: Graphics.drawArc需要以下参数:

  • x X
  • y ÿ
  • width 宽度
  • height 高度
  • startAngle 由startAngle
  • arcAngle 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. 这为您提供了足够的信息来提供参数:x,y,width和height。

You haven't specified the desired angle so I guess you could choose one arbitrarily. 你没有指定所需的角度,所以我猜你可以任意选择一个。

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

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