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

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

问题描述

我在画布上有两个点,现在我可以使用

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

这段代码canvas.drawLine(p1.x, p1.y, p2.x, p2.y,paint);

我想画两点之间的圆弧,如下图.

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

我怎么能画成这样.

推荐答案

最后我从这段代码中得到了解决方案:

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,请使用以下代码:

To calculate startAngle, use this code:

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

此处,point1 表示您要开始绘制圆弧的位置.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天全站免登陆