在圆石中将圆分成n个相等的一半的点的坐标 [英] Coordinates of points dividing circle into n equal halves in Pebble
问题描述
我正在尝试使用直线将圆分成n个相等的部分.想法是获取圆圆周上端点的坐标,然后绘制直线.
I am trying to divide the circle into n equal parts using straight lines. Idea is to get the coordinates of the end points on the circumference of the circle and then to draw the line.
要找到我的配伍酸盐,我正在使用以下代码:
to find coodrinates I am using following code:
static void getPoints(int x0,int y0,int r)
{
double angle = 0;
double angleToRadian = 0;
for(int i = 0 ; i < noOfDividingPoints ;i++)
{
angle = i * (360/noOfDividingPoints);
angleToRadian = ( angle * 3.141 ) / 180;
APP_LOG(APP_LOG_LEVEL_DEBUG, "LOG: Angle: %lf, AngleToRadian: %lf", angle, angleToRadian );
x[i] = (int) (x0 + r * cos_lookup(angleToRadian));
y[i] = (int) (y0 + r * sin_lookup(angleToRadian));
APP_LOG(APP_LOG_LEVEL_DEBUG, "LOG: i: %d, x[i]: %d, y[i]: %d", i, (int)x[i], (int)y[i] );
}
}
使用此getPoints方法,我要填充数组x []和y [],然后遍历这些数组以在x [i]和y [i]之间绘制线
Using this getPoints method I am filling the array x[] and y[] and then iterate over these arrays to draw lines between x[i] and y[i]
但是,从上面的代码计算出的值很奇怪,下面是打印x []和y []内容的日志
However, the values calculated from the above code comes out to be weird, below are the logs printing the contents of x[] and y[]
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:57] WatchFace.c:45> LOG: i: 0, x[i]: 4587522, y[i]: 84
[14:18:57] WatchFace.c:36> LOG: Angle: 90
[14:18:57] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 1, x[i]: 4587522, y[i]: 84
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 2, x[i]: 4587452, y[i]: 504
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 3, x[i]: 4587452, y[i]: 924
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 4, x[i]: 4587452, y[i]: 1344
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 5, x[i]: 4587452, y[i]: 1344
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 6, x[i]: 4587452, y[i]: 1834
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 7, x[i]: 4587452, y[i]: 2254
请指出我在这里想念的东西.
Please point out what I am missing here.
谢谢.
推荐答案
lookup- Pebble中的正弦和余弦函数不采用弧度或度数表示角度;他们使用归一化为TRIG_MAX_ANGLE
的整数角,它对应于一个完整的圆或360°.
The lookup-functions for sine and cosine in Pebble don't take the angle in radians or degrees; they use an integer angle normalized to TRIG_MAX_ANGLE
, which corresponds to a full circle or 360°.
这同样适用于返回值,它是一个带符号的int,必须使用TRIG_MAX_RATIO
进行标准化才能获得有效的余弦或正弦.
The same applies to the returned value, which is a signed int that must be normalized with TRIG_MAX_RATIO
to get a valid cosine or sine.
因此,您应该可以执行类似的操作.
So you should be able to do something like this.
for (int i = 0; i < n ; i++) {
int32_t angle = i * TRIG_MAX_ANGLE / n;
x[i] = x0 + (r * cos_lookup(angle)) / TRIG_MAX_RATIO;
y[i] = y0 + (r * sin_lookup(angle)) / TRIG_MAX_RATIO;
}
请注意,所有计算都是使用整数完成的.请注意先相乘然后相除,以免截断结果.例如
Note that all calculations are done with integers. Take care to multiply first and then divide, so that you don't truncate results. For example,
cos_lookup(angle) / TRIG_MAX_RATIO
将始终产生零,除非角度等于0°或180°.
will always yield zero, except when the angle corresponds to 0° or 180°.
您可能还想看看上面链接的页面上的时针示例.
You also might want to have a look at the clock hand example on the page linked above.
这篇关于在圆石中将圆分成n个相等的一半的点的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!