我在画布上有两个点,现在我可以使用以下方法在这些点之间画一条线,如下图所示
This code canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
![enter image description here](https://i.stack.imgur.com/FyMi3.png)
我想在两点之间绘制圆弧,如下图所示。
![enter image description here](https://i.stack.imgur.com/he2zj.png)
我怎么能画成这样呢。
最后我从这段代码中得到了解决方案:
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
,使用此代码:
int startAngle = (int) (180 / Math.PI * Math.atan2(point.y - point1.y, point.x - point1.x));
Here, point1
表示要开始绘制圆弧的位置。sweepAngle
表示两条线之间的角度。我们必须使用两个点(例如我的问题图像中的蓝点)来计算它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)