1.x三次方和x三分之一次方

#include <GL/glut.h>
#include <math.h>
void myDisplay(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 0.5f, 1.0f);
glColor3f(0.5f, 0.1f, 1.0f);
glBegin(GL_LINE_STRIP);
for (i = 0; i < 1000; i++) // 画 x 三分之一次方
glVertex2f(i * 0.001, pow(i * 0.001, 0.33333333));
glEnd();
glBegin(GL_LINE_STRIP); // 画x三次方的
for (i = -1000; i < 0; i++)
glVertex2f(i * 0.001, pow(i * 0.001, 3));
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("复合函数");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
运行结果

2半立方抛物线
#include <GL/glut.h>
#include <math.h>
void myDisplay(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.1f, 0.7f, 0.2f, 0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_LINE_STRIP);
for (i = 0; i < 1000; i++)
glVertex2f(i * 0.001, sqrt(pow(0.9 * i * 0.001, 3)));
glEnd();
glBegin(GL_LINE_STRIP);
for (i = 0; i < 1000; i++)
glVertex2f(i * 0.001, -sqrt(pow(0.9 * i * 0.001, 3)));
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("半立方抛物线");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}

3.概率曲线
#include <GL/glut.h>
#include <math.h>
void myDisplay(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 1.0f, 0.5f, 1.0f);
glColor3f(0.5f, 0.0f, 1.0f);
glBegin(GL_LINE_STRIP);
for (i = -1000; i < 1000; i++)
glVertex2f(i * 0.001, pow(2.718281828459, -pow(i * 0.001, 2)) - 0.2);
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("概率曲线y=e^-(x^2)");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}

4.ln(|x|)
```cpp
#include <GL/glut.h>
#include <math.h>
void myDisplay(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.5f, 0.7f, 0.5f);
glColor3f(0.9f, 0.7f, 1.0f);
gluOrtho2D(-3, 3, -3, 3);
glBegin(GL_LINE_STRIP);
for (i = -30000; i < 30000; i++){
if (i == 0) continue;
glVertex2f(i * 0.001, log(fabs(i * 0.001)));
}
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("ln(|x|)");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}

最后
以上就是虚幻电灯胆最近收集整理的关于OpenGL绘制几个基本初等函数图像的全部内容,更多相关OpenGL绘制几个基本初等函数图像内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复