Circle Drawing Algorithm

Back to General discussions forum

Rodion (admin)     2022-09-08 21:24:35
User avatar

That's impressive - 20 minutes after the task is published, "tigers" are on it :)

Honestly, while I know it is said to be solved by "amendment" to Bresenham's line algorithm, wikipedia lacks corresponding article and I couldn't immediately find good explanation besides several implementations giving formulas without idea.

So I myself come up with some method close or resembling, but formulas not matching whatever I can find in the web. It passes the tests, but I'm not 100% sure in its correctness. Shall push my solution bit later.

Checker itself does not rely on any trickery integer algorithm, blatantly verifying points against those calculated with floats and rounding.

fellows of codeabbey attacking new problem

zelevin     2022-09-08 21:35:25

Immortalized!!!

Anyway, for me the (integer-only) solution was straightforward, but I ran into some (unexpected) challenges with the stopping criterion.

Good problem. Makes you take things like graphic primitives less for granted.

gardengnome     2022-09-08 21:42:57
User avatar

Slightly longer solution trying to avoid multiplications. :)

Rodion (admin)     2022-09-08 22:55:01
User avatar

with the stopping criterion

I think I too run into this much to my surprise, it's not always dx=dy... :)

trying to avoid multiplications

He-he, these y + y are amusing, but...

After my comment in the previous thread, I sat pondering how exactly more complicated is "simple" addition of two number compared to multiplication/division by powers of 2 (performed with shifts).

How shift works - it is what I understand easily. Shift register just feeds every next (or previous) bit from neighboring one and they are updated simultaneously on clock pulse. Shift by n bits shall take n clock pulses of course, but that seems tolerable.

But what about addition? adding two bits is clear enough - we can write logic functions to calculate 2-bit result. However the highest bit of this result is carry, which should be added to the next bit. This means that without some trick simple adding of n-bit values shall take n clock cycles at least. I browsed internet and wikipedia and found out there is an advanced approach overcoming this inefficiency, but resulting logic is so much more complicated compared to shift register!

Well, all this makes me think it would be cool to create some "follow-up" to few problems in the "logic" category we had some time ago, but I'm not quite sure yet how this could/should be implemented.

Makes you take things like graphic primitives less for granted.

Hm-m-m... good hint, what other primitives we know? I have no idea how to draw an ellipse for example, but perhaps it is worth to check how flood fill is performed! I'll see... :)

Please login and solve 5 problems to be able to post at forum