如何在画布两点之间画弧? [英] How to draw Arc between two points on the Canvas?

查看:1438
本文介绍了如何在画布两点之间画弧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于如何在画布两点之间画弧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆