开发者

"Drawing" an arc in discrete x-y steps

开发者 https://www.devze.com 2023-02-01 01: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开发者_如何学JAVA radius 4 at point (4,4). Let\'s saw my \"drawer\" starts at

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开发者_如何学JAVA 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号