Android的划分圆分成N个相等的部分,并了解每个分割点的坐标 [英] android Dividing circle into N equal parts and know the coordinates of each dividing point

查看:344
本文介绍了Android的划分圆分成N个相等的部分,并了解每个分割点的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有要求,即基于数(2,3圆应分成N等份,...,N。但我想分点的坐标。

I have requirement that a circle should be divided into N equal parts based on number(2,3...n. But I want the coordinates of dividing points.

我有一个圆,中心(X,Y)半径(150)是已知的。

I have a circle whose centre(x,y) and radius(150) are known.

问:

Question:

有没有什么公式,给我分点的坐标如图所示。谁能告诉我该公式。我希望在Java中的实现它。

做参考圆图:

Circle image for refrence:

推荐答案

您需要<一个href="http://en.wikipedia.org/wiki/Circular_coordinates#Converting_between_polar_and_Cartesian_coordinates"相对=nofollow>转换 和的直角坐标。您需要的角度是一个分割一半的圆的(虚)垂直线和连接该中心与圆的边界线之间的角度。这个公式可以从中心计算X和Y偏移量。

You need to convert between polar and Cartesian coordinates. The angle you need is the angle between the (imaginary) vertical line that splits the circle in half and the line that connects the center with the circle's boundary. With this formula you can calculate the X and Y offsets from the center.

在您的示例图像的第一角度是0,而第二个是360 / N。每个其次是 I *(360 / N)其中i是需要绘制当前行的索引。运用这会给你按顺时针顺序X和Y偏移量(和你可以将它们添加到X和中心Y坐标找到每个点的坐标)

In your example image the first angle is 0, and the second one is 360/n. Each next is i*(360/n) where i is the index of the current line you need to draw. Applying this will give you the X and Y offsets in a clockwise order (and you can just add them to the X and Y coordinates of the center to find the coordinates of each point)

编辑:某种伪code:

some kind of pseudo-code:

//x0, y0 - center's coordinates
for(i = 1 to n)
{
    angle = i * (360/n);
    point.x = x0 + r * cos(angle);
    point.y = y0 + r * sin(angle);
}

这篇关于Android的划分圆分成N个相等的部分,并了解每个分割点的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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