Sign in to follow this  
bnf

Finding a set of even spaced points on a circle?

Recommended Posts

SiCrane    11839
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 / 7
point = []
for i in range(0, 6)
point.append( Point(sin(angle * i), cos(angle * i)) )

Share this post


Link to post
Share on other sites
JY    289
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

.
.
.

Share this post


Link to post
Share on other sites
bnf    138
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 / 7
point = []
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.

Share this post


Link to post
Share on other sites
bnf    138
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.

Share this post


Link to post
Share on other sites
King of Men    394
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.

Share this post


Link to post
Share on other sites
bnf    138
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this