2010-04-23 107 views
1

我認爲我自己是MATLAB的初學者,所以如果我的問題的答案是明顯的答案,那麼請耐心等待。2個曲面的MATLAB交集

Phi=0:pi/100:2*pi; 
Theta=0:pi/100:2*pi; 
[PHI,THETA]=meshgrid(Phi,Theta); 

R=(1 + cos(PHI).*cos(PHI)).*(1 + cos(THETA).*cos(THETA)); 
[X,Y,Z]=sph2cart(THETA,PHI,R); 
surf(X,Y,Z); %display 

hold on; 

x1=-4:.1:4; 
[X1,Y1] = meshgrid(x1); 
a=1.8; b=0; c=3; d=0; 
Z1=(d- a * X1 - b * Y1)/c; 
shading flat; 
surf(X1,Y1,Z1); 

我寫了這個代碼圖表以一角度交叉的花生形狀的物體的平面的三維笛卡爾圖。

我需要得到這些2D上的交點(將成爲一個花生的輪廓,但有點扭曲,因爲交叉發生在一個角度),但不知道如何。

感謝

回答

3

如果你只想得到相交的曲線,你可以將你的面的座標到平面的方程,發現在平面內幾乎躺在點。

%# find the distance of `X,Y,Z` to the plane 
dist2plane = a*X(:)+b*Y(:)+c*Z(:)-d; 

%# find index of the small distances 
lowDistIdx = abs(dist2plane)<0.05; %# or some other distance threshold 

%# plot the result - note that it's not quite a peanut 
figure,plot3(X(lowDistIdx),Y(lowDistIdx),Z(lowDistIdx),'.') 

如果要在2D中使用這些座標,則需要進行座標變換。