Finding a set of even spaced points on a circle?

Started by
6 comments, last by bnf 18 years, 8 months ago
What's the quickest way to arrange a set of points or objects in a circle, evenly spaced?
Advertisement
In terms of computer programming, take 2 Pi, divide by the number of points, and use sin and cos on multiples of that angle to create the points. e.g.:
angle = 2 PI / 7point = []for i in range(0, 6)  point.append( Point(sin(angle * i), cos(angle * i)) )
If I understand the question right, divide 360 by the number of objects to find the number of degrees between each one.

So, 2 objects will be placed 180 degrees apart
3 - 120 degress apart
4 - 90
5 - 72
6 - 60

.
.
.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Quote:Original post by SiCrane
In terms of computer programming, take 2 Pi, divide by the number of points, and use sin and cos on multiples of that angle to create the points. e.g.:
angle = 2 PI / 7point = []for i in range(0, 6)  point.append( Point(sin(angle * i), cos(angle * i)) )


Yeah this is what I have and its creating a circle, but when I place objects at those points by translating them there, they are not perfectly spaced. Some are showing up closer than others.
Sounds like rounding errors. If you're using ints, try using floats instead.

GDNet+. It's only $5 a month. You know you want it.

Quote:Original post by Tom
Sounds like rounding errors. If you're using ints, try using floats instead.


Yeah I'm using floats and still having the problem. One thing worth noting is that sin(angle * i), cos(angle * i)) does not create a value large enough for the size of the spheres i'm trying to render, so I multiplied it by 10. That shouldn't be an issue though.
You haven't given your sine function degrees when it was expecting radians, or something really obvious like that? By the way, how bad is the non-uniformity? If it's a pixel or two, it could easily be roundoff error in translating the floats to screen coordinates. And by the way, you are using inbuilt PI values, and not (say) your own #define'd PI = 3.14, or anything?

Edit : Oh, by the way, are you perhaps moving the lower-left corner of your object to the given point? That might give you a bit of trouble if the object is of non-negligible size compared to the circle's radius. Try changing your objects to points and see how that works.
To win one hundred victories in one hundred battles is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Ok, working now, stupid error was preventing it.

The issue now is that the circle starts at the origin and sweeps around towards positive X axis, but sweeps Y in both positive and negative. Meaning, the center of the circle is not the origin, which is what I want.

This topic is closed to new replies.

Advertisement