0

我正在使用 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 必须是一个矩阵,我有点迷茫。

4

2 回答 2

1

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

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

于 2016-07-21T11:47:56.407 回答
1

3D 打印需要使用 3D 文件格式,例如 stl(最常见)、stp、amf、obj 或参数化刀具路径 (Gcode)。您可以导出它的参数形式来控制 3D 打印机的运动,但实际上您不会打印任何东西。如果要导出一个stl,就必须创建大量的facets(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
于 2016-07-28T23:57:16.337 回答