找到你要的答案

Q:Approximate position on circle for n points

Q:n点圆上的近似位置

I am struggling with the following problem: I am given n points and a radius and I have to place them on a circle as symmetrical as possible.

Currently, I used something like this:

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++;
}

where n is my number of points.

This works fine for a large enough n, but for n=3 for example, I get something like:

I would actually like to have something like:

(bad drawing skills are bad..)

So basically, something as symmetric as possible would be awesome.

Any hints on how to solve this?

Thanks <3

I am struggling with the following problem: I am given n points and a radius and I have to place them on a circle as symmetrical as possible.

目前,我用了这样的东西:

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

answer1: 回答1:

Thanks to Jongware, the answer was quite obvious. Because I'm dealing with Java, all the sin/cos parameters should be in radians. Fix:

double newX = Math.sin(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_X;
double newY = Math.cos(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_Y;

Works like a charm

Thanks to Jongware, the answer was quite obvious. Because I'm dealing with Java, all the sin/cos parameters should be in radians. Fix:

double newX = Math.sin(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_X;
double newY = Math.cos(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_Y;

作品如魅力

geometry  computational-geometry  approximation