2017-01-23 50 views
0

我試圖使用表面 p顛簸球體和在Matlab皺球體= 1 + 0,2 * SIN(披* M)* SIN(TETA * N)顛簸和皺球在Matlab

teta = 0:6.23; 
    phi = 0:3.14; 
    [teta,phi] = meshgrid(teta, phi); 
    figure, hold on 
    for m = 1:12 
     for n = 1:12 
      p = 1 + 0.2*sin(m*teta).*sin(n*phi); 
      surf(teta,phi,p) 
      pause(0.05) 
      clf('reset') 
     end 
    end 

但它不繪製任何球體只是表面......我做錯了什麼,我應該改變什麼:)謝謝!

+0

好吧,你傳遞球面座標'surf'只處理直角座標系。先轉換它們。 – Suever

+0

我應該怎麼做@Suever ....我對matlab很新穎......你能幫我解決這個問題嗎? :) –

+0

也許[這篇文章](http://stackoverflow.com/questions/30089707/i-need-help-graphing-a-spherical-equation-in-cartesian-coordinates-in-matlab)可能是有用的 – gaetano

回答

1

我不明白你的榜樣,所以我創建了一個新問題:

%We define the spherical coordinates. 
theta = linspace(0,2*pi,50); 
phi  = linspace(0,pi,50); 
[x1,x2] = meshgrid(linspace(0,12*pi,50),linspace(0,12*pi,50)); %the variation of rho will produce a bumpy sphere. 
rho  = 0.1*(sin(x1)+cos(x2))+1; 
[theta,phi] = meshgrid(theta,phi); 

%we calculate the cartesian coordinates. 
x = rho.*cos(theta).*sin(phi); 
y = rho.*sin(theta).*sin(phi); 
z = rho.*cos(phi); 

%plot 
surf(x,y,z); 

結果顛簸

enter image description here

結果皺

簡單地改變RHO參數:

rho  = 0.1*(sin(x1))+1; 

enter image description here