0

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:

n=3

I would actually like to have something like:

enter image description here

(bad drawing skills are bad..)

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

Any hints on how to solve this?

Thanks <3

user1118321
  • 25,567
  • 4
  • 55
  • 86
Alexandr
  • 708
  • 9
  • 29
  • What language is this? (And, possibly relevant, what graphic library?) Does it actually use degrees for `sin` and `cos`, as you seem to assume? – Jongware May 02 '15 at 08:23
  • `Java` and `jgraphx` and yes, I assume they work with degrees but I could indeed be wrong – Alexandr May 02 '15 at 08:24
  • 1
    Well, that was easy. http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html: "**cos** .. Parameters: a - an angle, in radians." – Jongware May 02 '15 at 08:27
  • epic facepalm on my side. of course, it worked. thank you! – Alexandr May 02 '15 at 08:38

1 Answers1

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

Alexandr
  • 708
  • 9
  • 29