opengl绘制余弦函数,并显示坐标轴
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 06:20:06
opengl绘制余弦函数,并显示坐标轴
opengl绘制余弦函数,并显示坐标轴
opengl绘制余弦函数,并显示坐标轴
void DrawAxis(float r=3, float dr=1/24.){float dv=r*dr,dp=r-dv*3;
glBegin( GL_LINES);
glColor3f(1,0,0); // x轴glVertex3f(-r, 0, 0); glVertex3f(r, 0,0);
glVertex3f(dp,dv,0); glVertex3f(r,0,0);
glVertex3f(dp,-dv,0); glVertex3f(r,0,0);
glColor3f(0, 1, 0); // y轴glVertex3f( 0, -r, 0); glVertex3f( 0, r, 0);
glVertex3f(-dv, dp, 0); glVertex3f( 0, r, 0);
glVertex3f( dv, dp, 0); glVertex3f( 0, r, 0);
glColor3f(0, 0, 1); // z轴glVertex3f( 0, 0, -r); glVertex3f( 0, 0, r);
glVertex3f(-dv, 0, dp); glVertex3f( 0, 0, r);
glVertex3f( dv, 0, dp); glVertex3f( 0, 0, r);
glEnd();}
void drawFunc(FUNCPTR f, double*I){ static double Iab[]={0, 2*PI, }; static int ic=100, s=1; // s=scale
if(!I) I=Iab;
double dx=Iab[1]-Iab[0]; dx/=ic; // dx=取样步长
static float co[]={1,0,0, 0,1,0, 0,0,1, 1,1,1, }; static double x,y=0,z=0;
x=0; // 注意 static 变量初始化的问题
glBegin( GL_LINE_STRIP ); // 以线段形式绘制 GL_LINES
for(int i=0;i