如何在画布两点之间画弧?画布、两点、如何在

2023-09-12 04:14:22 作者:狂奔的小短腿i

我有两个点在画布上,现在我能够通过使用绘制这些点像这样下面的图片之间的行

I have two points in the canvas, now I'm able to draw a line between those points like this below image by using

这code canvas.drawLine(p1.x,p1.y,p2.x,p2.y,油漆);

This code canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);

我要画两个点之间的弧像下面的图像。

I want to draw the arc between two points like below image.

我怎么能得出这样的。

推荐答案

最后,我得到了这个code解决方案:

Finally I got the solution from this code:

float radius = 20;
final RectF oval = new RectF();
oval.set(point1.x - radius, point1.y - radius, point1.x + radius, point1.y+ radius);
Path myPath = new Path();
myPath.arcTo(oval, startAngle, -(float) sweepAngle, true);

要计算由startAngle ,使用code:

To calculate startAngle, use this code:

int startAngle = (int) (180 / Math.PI * Math.atan2(point.y - point1.y, point.x - point1.x));

下面,点1 表示要开始绘制圆弧。 sweepAngle 表示两条线之间的夹角。我们必须计算出,通过使用两个点,如蓝色的点在我的问题的形象。

Here, point1 means where you want to start drawing the Arc. sweepAngle means the angle between two lines. We have to calculate that by using two points like the blue points in my Question image.