用2点和圆心绘制圆弧 [英] Draw arc with 2 points and center of the circle

查看:560
本文介绍了用2点和圆心绘制圆弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个圆圈和圆圈的中心。我想在这些点之间画一条弧。方法 drawArc 很简单,不符合我的目的。
有人帮忙吗?

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. Anybody help?

推荐答案

你可以使用Canvas.drawArc,但你必须计算它需要的参数:

You can use Canvas.drawArc, but you must compute the arguments it needs:

假设圆的中心是(x0,y0)并且弧包含你的两个点(x1,y1)和(x2,y2)。然后半径为:r = sqrt((x1-x0)(x1-x0)+(y1-y0)(y1-y0))。所以:

Lets say that the center of the circle is (x0, y0) and that the arc contains your two points (x1, y1) and (x2, y2). Then the radius is: 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);

祝你好运!

这篇关于用2点和圆心绘制圆弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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