Author Topic: Problem with circle generator.  (Read 1471 times)

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?

This is the method I have used to do circles

Code: [Select]
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...
}
}
}
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.

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?

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?

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.

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.
alright

if you're just doing fillins, can't you just make a grid and check if each brick is in the circle/oval or not?
it'd make doing ovals easy :D

There's gaps because you're only making 360 bricks.

There's gaps because you're only making 360 bricks.
oh, so he's making a big circle? i thought he was making a small one

Yeah they were pretty big.

And as for the uneven problem. You're using the player as the origin. The player does not snap to the grid like bricks do. You need to use a snapped point of the grid for an origin, for example, a starter brick.

Yeah they were pretty big.

And as for the uneven problem. You're using the player as the origin. The player does not snap to the grid like bricks do. You need to use a snapped point of the grid for an origin, for example, a starter brick.
Alright. I added in a parameter to scale down the circles because they were so big, thanks for clearing up the crookedness problem.


There's gaps because you're only making 360 bricks.
Yeah.

Yeah they were pretty big.

And as for the uneven problem. You're using the player as the origin. The player does not snap to the grid like bricks do. You need to use a snapped point of the grid for an origin, for example, a starter brick.
or you could set the starter position to variables, and round down/up

or you could set the starter position to variables, and round down/up
since it uses mSin and mCos, rounding would really screw it up

since it uses mSin and mCos, rounding would really screw it up
i meant rounding the players position


I already do that.
then how would it be doing...
since it uses mSin and mCos, rounding would really screw it up