TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Bresenham's Circle Drawing Algorithm (2021)

107 pointsby RojerGS9 months ago

7 comments

corysama9 months ago
Do note that Bresenham’s family of algorithms (and much of the venerable Computer Graphics Principles and Practice) are from a bygone era where computers executed 1 instruction per cycle without pipelining or prediction.<p>These days processors prefer to draw shapes by having a coarse grained pass that conservatively selects tiles of interest then brute-force evaluates each pixel in each tile independently of all others.<p>Instead of minimizing total work, the goal is to maximize pipelined parallelism while skipping over unnecessary work in large blocks.
评论 #41407336 未加载
评论 #41409870 未加载
评论 #41407076 未加载
评论 #41407366 未加载
评论 #41413681 未加载
评论 #41407192 未加载
评论 #41408117 未加载
评论 #41409496 未加载
评论 #41412016 未加载
possiblywrong9 months ago
&gt; Note that if F(x,y)=0, then the point (x,y) is exactly on the circle. If F(x,y)&gt;0, then the point is outside of the circle, and if F(x,y)&lt;0 then the point is inside of it. <i>In other words, given any point (x,y), F(x,y) is the distance from the true circle line</i> [my emphasis].<p>This last is not quite true. The exact distance from the circle, call it G(x,y), is the corresponding difference of square roots, i.e.,<p><pre><code> def G(x, y, r): return math.sqrt(x * x + y * y) - math.sqrt(r * r) </code></pre> and G(x,y) isn&#x27;t just the square root of F(x,y), and indeed doesn&#x27;t behave monotonically with respect to F(x,y).<p>It&#x27;s an interest property of Bresenham&#x27;s algorithm, that I&#x27;ve never seen even stated let alone proved in the literature, that this doesn&#x27;t matter, and the algorithm is indeed exact in the sense that it always chooses the next point based on which is <i>truly</i> closest to the circle... despite using an error function that is only an approximation.
bsenftner9 months ago
My computer graphics professor back in the early 80&#x27;s was Prof. Glen Bresenham, but not The Bresenham. It was a lot of fun being at SIGGRAPH back then and watching people freak upon reading his name badge. He&#x27;d let them believe for a bit, and then explain it&#x27;s not him. Al Acorn was one that freaked, and that was fun.
评论 #41413960 未加载
KingOfCoders9 months ago
What I found most amazing about Bresenham during my Amiga days, is how you can use it to zoom and shrink bitmaps.
nikolay9 months ago
This is easy; anti-aliasing is thougher. I used this algorithm in the &#x27;90s to come up with one for drawing ellipses. I&#x27;ve never had to do a disc or filled ellipse with or without outloune, but that would be interesting, too. Line size &gt; 1 would be interesting as well.
seanhunter9 months ago
Feels like simply using the parametric form of the circle equation would be way easier<p>For t in 0 to 2 pi in whatever small steps you want, draw_pixel(x=a+rcos t, y=b+rsin t) where a and b are the x and y coordinates you want for the centre of the circle and r is the radius.<p>The derivation of this form is pretty simple if you know basic trig. <a href="https:&#x2F;&#x2F;publish.obsidian.md&#x2F;uncarved&#x2F;3+Resources&#x2F;Public&#x2F;Unit+Circle+Definitions+of+Trigonometric+Functions" rel="nofollow">https:&#x2F;&#x2F;publish.obsidian.md&#x2F;uncarved&#x2F;3+Resources&#x2F;Public&#x2F;Unit...</a>
ericyd9 months ago
A cool write up with an approachable explanation of algorithm optimization! I wonder how long it would take me to arrive at this algorithm left to my own devices...