#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <dos.h>
int main() {
int gd = DETECT, gm;
int angle = 0;
double x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");
line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2);
/* generate a sine wave */
for(x = 0; x < getmaxx(); x+=3) {
/* calculate y value given x */
y = 50*sin(angle*3.141/180);
y = getmaxy()/2 - y;
/* color a pixel at the given position */
putpixel(x, y, 15);
delay(100);
/* increment angle */
angle+=5;
}
getch();
/* deallocate memory allocated for graphics screen */
closegraph();
return 0;
}
这就是程序。为什么我们要增加Angular ,这个Angular 与图形有什么关系?我把Angular 的值改为0,波就变成了一条直线。我想知道这个增量会发生什么。
1条答案
按热度按时间nbysray51#
为什么我们要增加这个Angular ,这个Angular 与图形有什么关系
sine function以一个Angular 作为参数,通常以辐射角为单位。程序以度为单位实现Angular ,因此它被缩放为辐射角,时刻被传递给
sin()
。正弦函数是周期性的(在2*pi或360度之后重复自身):
我将Angular 的值更改为0,波变成了直线
sin(0)
的结果是0
。For the mathematical derivation you might like to have a look here。