使用 MATLAB 3D 打印洛伦兹吸引子
3D printing the Lorenz Attractor using MATLAB
我正在使用 MATLAB 绘制洛伦兹吸引子,想知道如何将 XYZ 坐标导出到 3D 可打印文件!我在从 XYZ 坐标到表面时遇到问题(我应该这样做吗?)。此外,即使将 Lorenz Attractor 视为 "surface" 对我来说似乎也不正确,因为我的理解是它更像是 "path."
到目前为止我的代码:
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必须是矩阵,我有点迷路了。
mesh
无法工作,因为您正在绘制曲线。 Mesh 需要矩阵作为输入。
要绘制曲线,您可以使用 plot3
。试试这个:
figure;
plot3(x, y, z);
grid on
3D 打印需要使用 3D 文件格式,例如 stl(最常见)、stp、amf、obj 或参数化刀具路径 (Gcode)。你可以导出它的参数形式来控制 3D 打印机的运动,但你实际上不会打印任何东西。如果要导出stl,则必须创建大量的面(3D中的三角形space,法向量由右手叉积计算),并按以下格式输出:
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
我正在使用 MATLAB 绘制洛伦兹吸引子,想知道如何将 XYZ 坐标导出到 3D 可打印文件!我在从 XYZ 坐标到表面时遇到问题(我应该这样做吗?)。此外,即使将 Lorenz Attractor 视为 "surface" 对我来说似乎也不正确,因为我的理解是它更像是 "path."
到目前为止我的代码:
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必须是矩阵,我有点迷路了。
mesh
无法工作,因为您正在绘制曲线。 Mesh 需要矩阵作为输入。
要绘制曲线,您可以使用 plot3
。试试这个:
figure;
plot3(x, y, z);
grid on
3D 打印需要使用 3D 文件格式,例如 stl(最常见)、stp、amf、obj 或参数化刀具路径 (Gcode)。你可以导出它的参数形式来控制 3D 打印机的运动,但你实际上不会打印任何东西。如果要导出stl,则必须创建大量的面(3D中的三角形space,法向量由右手叉积计算),并按以下格式输出:
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