用 制作一个圆。 (期间)
我正在尝试创建一个函数,该函数将在仅给出起始 x
和 y
以及半径的情况下绘制一个圆。可能吗?
我想要它的完整代码,并解释它是如何工作的;我已经尝试这个方法一年了,但我仍然无法理解它是如何完成的。
I am trying to make a function that will draw a circle out of periods with only being given a starting x
and y
and a radius. Is it possible?
I would like to have the full code for it will an explanation for how it works; I've been trying this for 1 year now and I still can't fathom how it may be done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是数学计算,甚至是 C 语言的示例程序:
http: //pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm(链接不再存在)。position:absolute
、left
和top
可以让你绘制:http://www.w3.org/TR/CSS2/visuren.html#choose-position
还有其他问题吗?
Here's the maths and even an example program in C:
http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm(link no longer exists).And
position: absolute
,left
andtop
will let you draw:http://www.w3.org/TR/CSS2/visuren.html#choose-position
Any further questions?
我知道你只要求周长,但做一个实心圆似乎更容易。
I know you asked for just the circumference, but it seemed easier to do a filled circle.
是的,这是可能的。将以下代码放入 html 文件中以查看其运行情况。
快速浏览一下:代码生成一系列点和空格。它根据当前 x, y 位置到圆心的距离是否小于或等于半径长度,通过距离公式 ( http://www.purplemath.com/modules/distform.htm )。
Yes, it is possible. Put the below code into an html file to see it in action.
A quick run through: The code generates an array of dots and spaces. It chooses to make a dot based on if the distance from the current x, y position to the center of the circle is less than or equal to the length of the radius via the distance formula ( http://www.purplemath.com/modules/distform.htm ).
您正在寻找Bresenham 圆算法。
You are looking for Bresenham's circle algorithm.