使用绘图三角实心圆 [英] Drawing filled circle using trigonometry

查看:163
本文介绍了使用绘图三角实心圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有我可以为了使用基本绘图功能绘制实心圆创建的任何功能:

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);

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

请注意,它必须用三角函数(换言之 COS 等)的所以我可以很容易地把它变成一个六边形,甚至进一步 - 一个正方形或其他类型的多边形

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.

最后,不一定但总是AP preciated如果它不在绘图很慢(一个回路应足以我presume)和甚至更不一定,但总是更加AP preciated如果不是太复杂和/或组成的多个行比所需的轻质生命

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.

推荐答案

要绘制了lineTo 实心圆是如下的最快方法

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)
}

在这里输入的形象描述

要圆转换为多边形就可以计算该多边形的基础上的圆的半径和角度到每个顶点的顶点。例如,用一个六边形的角是0,60,120,180,240,以及300度。一个正方形的角度为45,135,225,和315一旦你的多边形顶点,就可以计算出 X1 X2 Ÿcode>值基础上顶点之间的线方程值。

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.

在这里输入的形象描述

这篇关于使用绘图三角实心圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆