我想用OpenGL在3D空間中對Lorenz吸引子建模。我寫了下面的代碼在我的顯示功能:Lorenz在OpenGL中的吸引力
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
是正確的。我只是不確定如何以正確的方式顯示出正確的吸引子。謝謝你的幫助。下面是我的程序正在撲滅:
你好
你應該發佈你截至目前爲止的截圖。 –
我剛剛發佈了一個屏幕截圖 – Sean
沒有你發佈你的參數'dt' /'sigma' /'r' /'b',這很難說,但你是否嘗試插入示例圖像中的值: http://en.wikipedia.org/wiki/Lorenz_system#Analysis? –