“Drawing” an arc in discrete x-y steps

2019-07-20 15:59发布

What's the best way to draw an arc using only x-y position movements? For example let's say I want to draw a circle with radius 4 at point (4,4). Let's saw my "drawer" starts at (4,0) and a resolution of .1 steps in each direction. How would I create a sequence of movements to complete the circle?

If that's not clear I can try to explain better.

2条回答
做自己的国王
2楼-- · 2019-07-20 16:34

You want the midpoint circle algorithm, also known as Bresenham's circle algorithm (even though Bresenham didn't develop it). Wikipedia has a reasonably good article about it; there was also a Python implementation on the LiteratePrograms wiki (which is no more – the link is to the Wayback Machine), and several implementations on Rosetta Code. The idea behind it is to walk in a circle, successively computing each coordinate from the previous one (avoiding more expensive math operations). You always move in one direction (say "up"), and use the computed variable to decide whether or not to turn.

查看更多
等我变得足够好
3楼-- · 2019-07-20 16:35

If I understand your question properly, you are looking for Bresenham's algorithm. You can read about it here, for example.

查看更多
登录 后发表回答