This might be interesting to implement in assembly for any of you assembly heads out there. The idea here is to use derivative calculus concepts to get the next point position instead of calculating sqrt which is slow.
https://yurichev.com/news/20220322_circle/
Here is the final non-naïve algorithm (in case the article goes away):
function circle(x0, y0, radius) { // starting point: var x = radius; var y = 0; var err = 0; while (x >= y) { // main octant: putPixel(x0 + x, y0 + y); // copy octant 7 times: putPixel(x0 + y, y0 + x); putPixel(x0 - y, y0 + x); putPixel(x0 - x, y0 + y); putPixel(x0 - x, y0 - y); putPixel(x0 - y, y0 - x); putPixel(x0 + y, y0 - x); putPixel(x0 + x, y0 - y); // increase $y$ and update $err$ y += 1; err += 2*y + 1; // if $err$ is bigger than zero, decrease $x$ and update $err$ again // we do this to maintain the equation x^2 + y^2 - r^2 = 0 (for integer arithmetic) if (err > 0) { x -= 1; err -= 2*x + 1; } } };
Just additions, subtractions and bit shifts.
Login sesión o register para postear comentarios