2016-07-21 64 views
0

我正在使用MATLAB來繪製洛倫茲吸引子並想知道如何將XYZ座標導出到3D可打印文件!從XYZ座標轉換到曲面我遇到了麻煩(我應該這樣做嗎?)。另外,即使將洛倫茲吸引子看作「表面」似乎也不適合我,因爲我的理解是它更像是一條「路徑」。到目前爲止我的代碼:使用MATLAB打印洛倫茲吸引子使用MATLAB

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必須是矩陣,我有點失落。任何幫助表示讚賞!謝謝

回答

1

mesh無法工作,因爲您正在繪製一條曲線。網格需要矩陣作爲輸入。 要繪製曲線,您可以使用plot3。試試這個:

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

1

3D打印需要使用的3D文件格式,如STL(最常見),STP,AMF,OBJ,或paramaterized刀具路徑(G代碼)。您可以導出其參數化形式來控制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