Drawing filled circle using trigonometry [duplicate]

若如初见. 提交于 2019-12-12 00:29:08

问题


Is there any function I can create in order to draw a filled circle using the base drawing functions:

  • putpixel(x, y);
  • lineto(x, y);

?


Note that it must use trigonometric functions (videlicet sin, cos etc..) so I can easily turn it into a hexagon and even further - a square or another type of polygon.


And finally, not necessarily but always appreciated if it isn't very slow in drawing (one loop should be enough I presume) and even more not necessarily, but always even more appreciated if it isn't too complex and/or consisting of more lines than needed for a lightweight life.


回答1:


The fastest way to draw a filled circle with lineto is as follows

for each value of y that lies within the circle
{
    compute the corresponding x values
    draw a line between (x1,y) and (x2,y)
}

To convert the circle to a polygon you can compute the vertices of the polygon based on the radius of the circles and angle to each vertex. For example, with a hexagon the angles are 0, 60, 120, 180, 240, and 300 degrees. With a square the angles are 45, 135, 225, and 315. Once you have the polygon vertices, you can compute the x1 and x2 values for each y value based on the equations of the lines between the vertices.



来源:https://stackoverflow.com/questions/31796026/drawing-filled-circle-using-trigonometry

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