n 个点在圆上的大概位置
Approximate position on circle for n points
我正在努力解决以下问题:
我得到 n
个点和一个半径,我必须将它们放在一个尽可能对称的圆上。
目前,我使用的是这样的:
float theta = 360.0f / n;
int i = 0;
for (Word w : e.getValue()) {
double newX = Math.sin(theta * i) * RADIUS + I_OFFSET_X;
double newY = Math.cos(theta * i) * RADIUS + I_OFFSET_Y;
mxCell v2 = (mxCell) graph.insertVertex(parent, null, w.getValue(), newX, newY, OW_WIDTH, OW_HEIGHT,"shape=ellipse");
graph.insertEdge(parent, null, "", v1, v2);
i++;
}
其中 n
是我的分数。
这对于足够大的 n 工作正常,但是对于 n=3
例如,我得到类似的东西:
我实际上想要这样的东西:
(画功不好是坏..)
所以基本上,尽可能对称的东西会很棒。
关于如何解决这个问题的任何提示?
谢谢 <3
感谢 Jongware,答案很明显。因为我正在处理 Java,所以所有 sin/cos
参数都应该以弧度为单位。
修复:
double newX = Math.sin(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_X;
double newY = Math.cos(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_Y;
很有魅力
我正在努力解决以下问题:
我得到 n
个点和一个半径,我必须将它们放在一个尽可能对称的圆上。
目前,我使用的是这样的:
float theta = 360.0f / n;
int i = 0;
for (Word w : e.getValue()) {
double newX = Math.sin(theta * i) * RADIUS + I_OFFSET_X;
double newY = Math.cos(theta * i) * RADIUS + I_OFFSET_Y;
mxCell v2 = (mxCell) graph.insertVertex(parent, null, w.getValue(), newX, newY, OW_WIDTH, OW_HEIGHT,"shape=ellipse");
graph.insertEdge(parent, null, "", v1, v2);
i++;
}
其中 n
是我的分数。
这对于足够大的 n 工作正常,但是对于 n=3
例如,我得到类似的东西:
我实际上想要这样的东西:
(画功不好是坏..)
所以基本上,尽可能对称的东西会很棒。
关于如何解决这个问题的任何提示?
谢谢 <3
感谢 Jongware,答案很明显。因为我正在处理 Java,所以所有 sin/cos
参数都应该以弧度为单位。
修复:
double newX = Math.sin(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_X;
double newY = Math.cos(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_Y;
很有魅力