Arc "drawing" in discrete xy steps

What is the best way to draw an arc using only xy position motions? For example, let's say I want to draw a circle with a radius of 4 at a point (4,4). Let him see that my β€œdrawer” begins with (4.0) and a resolution of 0.1 steps in each direction. How to create a sequence of movements to complete a circle?

If this is unclear, I can try to explain better.

+2
source share
2 answers

If I understand your question correctly, you are looking for the Breshenem algorithm. You can read about it here , for example.

+3
source

You need a circle circumference algorithm, also known as a Bresenham circle algorithm (although Bresenham did not develop it). Wikipedia is a good enough article about this; there was also a Python implementation on the LiteratePrograms wiki page (which is no longer a link to the Wayback Machine), but several implementations in the Rosetta Code. The idea is to walk in a circle, sequentially calculating each coordinate from the previous one (avoiding more expensive mathematical operations). You always move in one direction (say, up) and use the computed variable to decide whether to rotate it.

+2
source

Source: https://habr.com/ru/post/891324/


All Articles