“Drawing” an arc in discrete x-y steps

六眼飞鱼酱① 提交于 2019-12-11 03:31:05

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4537124/drawing-an-arc-in-discrete-x-y-steps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!