我正在尝试使用 OpenGL 在 3D 空间中对 Lorenz 吸引子进行建模。我在显示函数中编写了以下代码:
void display()
{
// Clear the image
glClear(GL_COLOR_BUFFER_BIT);
// Reset previous transforms
glLoadIdentity();
// Set view angle
glRotated(ph,1,0,0);
glRotated(th,0,1,0);
glColor3f(1,1,0);
glPointSize(1);
float x = 0.1, y = 0.1, z = 0.1;
glBegin(GL_POINTS);
int i;
for (i = 0; i < initialIterations; i++) {
// compute a new point using the strange attractor equations
float xnew = sigma*(y-x);
float ynew = x*(r-z) - y;
float znew = x*y - b*z;
// save the new point
x = x+xnew*dt;
y = y+ynew*dt;
z = z+znew*dt;
glVertex4f(x,y,z,i);
}
glEnd();
// Draw axes in white
glColor3f(1,1,1);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(1,0,0);
glVertex3d(0,0,0);
glVertex3d(0,1,0);
glVertex3d(0,0,0);
glVertex3d(0,0,1);
glEnd();
// Label axes
glRasterPos3d(1,0,0);
Print("X");
glRasterPos3d(0,1,0);
Print("Y");
glRasterPos3d(0,0,1);
Print("Z");
// Display parameters
glWindowPos2i(5,5);
Print("View Angle=%d,%d %s",th,ph,text[mode]);
// Flush and swap
glFlush();
glutSwapBuffers();
}
但是,我无法获得正确的吸引子。我相信我的x
, y
,等式z
是正确的。我只是不确定如何以正确的方式显示它以获得正确的吸引子。谢谢你的帮助。以下是我的程序目前正在推出的内容:
你好