2014年3月25日 星期二

不使用「內建畫圓」來畫圓 Drawing a circle without "drawing circle command"

圓的方程式是:
座標 x 的平方+ 座標 y 的平方 = 半徑 r 的平方

而由三角函數定義,我們可以得知 x,y 可由角度代表,故我們個得圓的參數式為:

x = rcos(theta)、y = rsin(theta)

將其代入原式可得 
rcos(theta)平方 + rsin(theta)平方 = r平方

= r 平方(cos(theta)平方+sin(theta)平方)

 = r 平方

左式的 cos(theta)平方+sin(theta)平方 = 1,故左式=右式

使用 PointOut(x,y,options)去在螢幕上畫點

範例:

task main()
{

float thata = 0;

int r = 1;


while(theta < 2*PI)
{

PointOut(r*cos(theta),r*sin(theta),false);
theta = theta + 0.01;

}
while(1){}
}