Blockland Forums > Modification Help

Problem with circle generator.

Pages: (1/4) > >>

otto-san:

For the most part, my circle generator works. However, it does leave random gaps in the circle and also is pretty uneven, one corner always being more box-like than the other.

http://dl.dropbox.com/u/11058668/circleGenerator.cs

Can this issue be fixed?

Nexus:

This is the method I have used to do circles


--- Code: ---function makecircle(%radius, %center)
{
for(%a=%radius*-1; %a<=%radius; %a++)
{
%chord = mfloor(msqrt(mpow(%radius, 2) - mpow(%a, 2))); //yay geometry

for(%b=%chord*-1; %b<=%chord; %b++)
{
%xf = %a + getword(%center, 0);
%yf = %b + getword(%center, 1);
//do stuff i guess...
}
}
}
--- End code ---
Note that this should also fill the circle in, not just outline it.

Looking at yours,  I am not sure if I entirely understand it (never seen mFloatLength() before), but it looks like you are limiting yourself to 360 points per circle, and at times jamming in more points than needed in smaller circles.  I think if you base the circles on triangles like in the method above instead of on the angles, you might get a bit cleaner of a circle.

otto-san:

I actually based it off of some Lua code, and you are correct when you say it's limited to 360 points.

the mFloatLength was put in to maybe make the position less exact but it ended up being noneffective.

Yours looks like it goes by having chords run through and make a circle, basically, is that right?

Nexus:


--- Quote from: otto-san on September 13, 2011, 10:44:06 PM ---I actually based it off of some Lua code, and you are correct when you say it's limited to 360 points.

the mFloatLength was put in to maybe make the position less exact but it ended up being noneffective.

Yours looks like it goes by having chords run through and make a circle, basically, is that right?

--- End quote ---

Yea, it basically just draws lines across between endpoints.  I am sure that it wouldn't be to difficult to adapt it to just making the endpoints instead of all the extra filler.  I took another look at your code, and I think that if you perhaps made your code so it adjusted the number of points (and the interval the points are on) based on the size of the circle, it would end up nice and clean, but that may end up being more work that needed.

otto-san:


--- Quote from: Nexus on September 13, 2011, 11:04:29 PM ---Yea, it basically just draws lines across between endpoints.  I am sure that it wouldn't be to difficult to adapt it to just making the endpoints instead of all the extra filler.  I took another look at your code, and I think that if you perhaps made your code so it adjusted the number of points (and the interval the points are on) based on the size of the circle, it would end up nice and clean, but that may end up being more work that needed.

--- End quote ---
alright

Pages: (1/4) > >>

Go to full version