使用MATLAB 3D打印Lorenz Attractor

时间:2016-07-21 01:56:37

标签: matlab math lorenz-system

我正在使用MATLAB绘制Lorenz吸引子,并想知道如何将XYZ坐标导出为3D可打印文件!我无法从XYZ坐标到表面(我应该这样做吗?)。此外,即使把Lorenz Attractor视为“表面”似乎也不适合我,因为我的理解是它更像是一条“道路”。到目前为止我的代码:

clear all; clc; clf;

dt = .01;
n = 100; %Number of Drawings
t = 0:dt:n; %Time Scale

%INITIAL CONDITIONS
x = 1;
y = 1;
z = 1;
xyz0 = [x y z];

%SOLVE ODE
[t,xyz] = ode45(@rhs, t, xyz0);

x = xyz(:,1);
y = xyz(:,2);
z = xyz(:,3);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%     PLOTTING    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%plot3(x,y,z);

rotate3d on;

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%         RHS FOR ODE45     %%%%%%%%%%%%%%%%%%%%%%%%
function xyzdot = rhs(t,xyz)

    sigma = 10;
    b     = 8/3;
    r     = 100;

    x = xyz(1);
    y = xyz(2);
    z = xyz(3);

    dxdt = sigma*(y - x);
    dydt = r*x - y - x*z;
    dzdt = x*y - b*z; 

    xyzdot = [dxdt; dydt; dzdt];

end

我之前尝试过这个:

[X,Y] = meshgrid(x,y);
surf(X, Y, z);

但没有任何效果。错误说z必须是一个矩阵,我有点迷失。任何帮助表示赞赏!谢谢,

2 个答案:

答案 0 :(得分:1)

mesh无法正常工作,因为您正在绘制曲线。 Mesh想要矩阵作为输入。 要绘制曲线,您可以使用plot3。试试这个:

figure;
plot3(x, y, z);
grid on

答案 1 :(得分:1)

3D打印需要使用3D文件格式,例如stl(最常见),stp,amf,obj或paramaterized工具路径(Gcode)。您可以导出此参数形式以控制3D打印机的运动,但您实际上不会打印任何内容。如果要导出stl,则必须创建大量构面(3D空间中的三角形,使用右手交叉积计算法线向量),并按以下格式输出:

solid keyminus.stl
 facet normal -0.676239558096412 0.628228242471799 0.384745806249222
  outer loop
   vertex 0 0 107.76627426733
   vertex 1.5625 1.5625 107.961254120119
   vertex 1.5625 0 110.512566214802
  endloop
 endfacet
 facet normal -0.678155426589519 0.63117863312972 0.37645550928056
  outer loop
   vertex 0 0 107.76627426733
   vertex 0 1.5625 105.146531455889
   vertex 1.5625 1.5625 107.961254120119
  endloop
 endfacet

.... (39,000 more facets here)

 facet normal 0 -1 0
  outer loop
   vertex 198.4375 0 0
   vertex 198.4375 0 110.512566214802
   vertex 200 0 107.76627426733
  endloop
 endfacet
 facet normal 0 -1 0
  outer loop
   vertex 198.4375 0 0
   vertex 200 0 107.76627426733
   vertex 200 0 0
  endloop
 endfacet
endsolid