Live data from Hacker News

Drawing a circle, point-by-point, without floating point support

yurichev.com

11–20 of 42 posts

Re: Drawing a circle, point-by-point, without floating point support

#12
post #5

You can always try Bresenham’s circle drawing algorithm.

This is the era where prior art doesn't exist. Why read a book when you can blog about discovering "something new". I could probably make a killing blogging about my "discovery" of the algorithms in the book "Hacker's Delight".

The author titled one of the sections "Midpoint circle algorithm".

There happens to be a Wikipedia page on "Midpoint circle algorithm": https://en.wikipedia.org/wiki/Midpoint_circle_algorithm

The page claims, "Bresenham's circle algorithm is derived from the midpoint circle algorithm."

The author of this blog post even made it clear, at the end of their article, that... "many explanations of midpoint algorithm use the final, optimized version. But I added several unoptimized steps."

I think there's a lot of value in a blogpost that demonstrates how someone could re-derive a widely-used algorithm from scratch.

Re: Drawing a circle, point-by-point, without floating point support

#13
post #11

I love Yurichev's books on assembly language, and he gives them away (CC-BY-4.0). https://beginners.re/

Actually that book is paywalled now. It's been somewhat of a controversy that people contributed to the book thinking it was a community resource but now it's unavailable.

Re: Drawing a circle, point-by-point, without floating point support

#14
post #8
post #5

You can always try Bresenham’s circle drawing algorithm.

Back in the '80s in Bulgaria, I was only able to find the Bresenham's algorithm for circles, but needed to draw an ellipse (in 6052 assembly, well, machine code), and was so proud that I manage to do it.

Did it work for any axes?

Re: Drawing a circle, point-by-point, without floating point support

#15
post #3

> It requires only additions, subtractions and bit shifts: 2x is the same as x Does any of this mean anything in JS, where AFAIK there are no real ints? 2x is an fpu operation under the hood, and not a bit shift.

I think, using the `(…) | 0` (expression binary ORed with zero) construct most JS engines will use true integers in optimized code.

In fact, the specification even guarantees that for all the bitwise operators.

Re: Drawing a circle, point-by-point, without floating point support

#16
post #14
post #8

Earlier quoted context omitted.

Back in the '80s in Bulgaria, I was only able to find the Bresenham's algorithm for circles, but needed to draw an ellipse (in 6052 assembly, well, machine code), and was so proud that I manage to do it.

Did it work for any axes?

As far as I can recall, yeah. By the way, I found this [0] implementation in pseudo code.

[0]: https://dai.fmph.uniba.sk/upload/0/01/Ellipse.pdf

Re: Drawing a circle, point-by-point, without floating point support

#18
post #3

> It requires only additions, subtractions and bit shifts: 2x is the same as x Does any of this mean anything in JS, where AFAIK there are no real ints? 2x is an fpu operation under the hood, and not a bit shift.

IEEE double-precision floating-point numbers can exactly represent 53-bit integers and hence they are suitable for most integer related operations (ignoring bitwise operations).

For bitwise operations, JavaScript will first convert the number to a 32-bit two's complement signed integer.

Re: Drawing a circle, point-by-point, without floating point support

#19
post #5

You can always try Bresenham’s circle drawing algorithm.

This is the era where prior art doesn't exist. Why read a book when you can blog about discovering "something new". I could probably make a killing blogging about my "discovery" of the algorithms in the book "Hacker's Delight".

This always blows my mind - for the first time in human history we live in a world where almost all prior art is relatively easily discoverable, and people don't even bother.

I guess I shouldn't be surprised, after all, I've met a lot of people.

Re: Drawing a circle, point-by-point, without floating point support

#20
post #11

I love Yurichev's books on assembly language, and he gives them away (CC-BY-4.0). https://beginners.re/

Actually that book is paywalled now. It's been somewhat of a controversy that people contributed to the book thinking it was a community resource but now it's unavailable.

wow. although the last time he updated the (singular) username and password was october. i think people could just ask around for it.

still, controversial indeed.

Weirdly, the book itself says:

> Q: May I print this book / use it for teaching? > A: Of course! That’s why the book is licensed under the Creative Commons license (CC BY-SA 4.0)

So it would be legal for anyone else to host this.

Post reply on HN