处理中的创造性编程|集2(洛伦兹吸引子)

处理中的创造性编程|集1(随机游走者) 洛伦兹系统是一个常微分方程系统,由美国数学家和气象学家爱德华·诺顿·洛伦兹在1963年左右首次研究。值得注意的是,对于某些参数值和初始条件,存在混沌解。它是从地球大气对流的简化模型推导出来的。它也自然出现在激光器和发电机的模型中。洛伦兹吸引子是洛伦兹系统的一组混沌解,当绘制时,它类似于蝴蝶或图8。下图出现在《自然》杂志2000年8月31日第949页上,是伊恩·斯图尔特(Ian Stewart)撰写的一篇题为《洛伦兹吸引子存在》(The Lorenz Attractor Exists)的文章的一部分。

null

图片[1]-处理中的创造性编程|集2(洛伦兹吸引子)-yiteyi-C++库

洛伦兹吸引子系统通常表示为3个耦合的非线性微分方程-

  • dx / dt = a (y - x)
  • dy / dt = x (b - z) - y
  • dz / dt = xy - c z

在上述方程组中,“a”有时被称为普朗特数,“b”是瑞利数。一组常用的常数是a=10,b=28,c=8/3。另一个是a=28,b=46.92,c=4。

java中微分方程的示例实现:-

int i = 0 ;
double x0, y0, z0, x1, y1, z1;
double h = 0.01 , a = 10.0 , b = 28.0 , c = 8.0 / 3.0 ;
x0 = 0.1 ;
y0 = 0 ;
z0 = 0 ;
for (i = 0 ; i < N; i++) {
x1 = x0 + h * a * (y0 - x0);
y1 = y0 + h * (x0 * (b - z0) - y0);
z1 = z0 + h * (x0 * y0 - c * z0);
x0 = x1;
y0 = y1;
z0 = z1;
// Printing the coordinates
if (i > 100 )
System.out.println(i + " " + x0 + " " + y0 + " " + z0);
}


我们将尝试在可视化处理Java时实现上述逻辑。因为我们将在3d中绘制点,所以我们需要使用3d渲染器。我们将在下面的实现中使用OPENGL渲染器,但也可以使用P3D渲染器。我们还需要使用一个名为PeasyCam的外部处理库,它可以帮助我们为3d环境工作流创建一个交互式相机对象。可以使用处理IDE从工具->添加工具->库下载PeasyCam。

我们还将使用以下函数来表示洛伦兹吸引子结构-

  • beginShape() –开始记录形状的顶点。
  • endShape() –停止记录形状的顶点。
  • vertex() –此函数用于指定点、线、三角形、四边形和多边形的顶点坐标。它只在公司内部使用 beginShape() endShape() 功能。

Lorenz吸引子在java处理中的实现:-

/* FINAL SKETCH FOR LORENZ ATTRACTOR */
import peasy.*; // Importing peasy package
// Initialization
float x = 0.01 , y = 0 , z = 0 ;
float a = 10 , b = 28 , c = 8.0 / 3.0 ;
// ArrayList of PVector objects to store
// the position vectors of the points to be plotted.
ArrayList<PVector> points = new ArrayList<PVector>();
PeasyCam cam; // Declaring PeasyCam object
void setup()
{
// Creating the output window
// and setting up the OPENGL renderer
size( 800 , 600 , OPENGL);
// Initializing the cam object
cam = new PeasyCam( this , 500 );
}
void draw()
{
background( 0 );
// Implementation of the differential equations
float dt = 0.01 ;
float dx = (a * (y - x)) * dt;
float dy = (x * (b - z) - y) * dt;
float dz = (x * y - c * z) * dt;
x += dx;
y += dy;
z += dz;
// Adding the position vectors to points ArrayList
points.add( new PVector(x, y, z));
translate( 0 , 0 , - 80 );
scale( 5 );
stroke( 255 );
noFill();
// Beginning plotting of points
beginShape();
for (PVector v : points) {
// Adding random color to the structure in each frame
stroke(random( 0 , 255 ), random( 0 , 255 ), random( 0 , 255 ));
vertex(v.x, v.y, v.z); // plotting the vertices
}
endShape(); // Drawing ends
}


输出:- 图片[5]-处理中的创造性编程|集2(洛伦兹吸引子)-yiteyi-C++库

源材料

本文由 苏米克·拉克什 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享