Finding a set of even spaced points on a circle?
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
.
.
.
So, 2 objects will be placed 180 degrees apart
3 - 120 degress apart
4 - 90
5 - 72
6 - 60
.
.
.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement