2011-11-06 53 views
1

一个功能我有一个函数在球形坐标来表示:MATLAB - 情节目前在表达球坐标系

f(r,theta,phi) = 4*exp(-r)*cos(theta)*sin(phi) 

我想通过这些方式绘制该在MATLAB:

  1. R3
  2. R2轮廓图(xy平面或xz平面或yz平面)

是否有直接的如何做到这一点?

回答

1

只是做转换和情节在笛卡尔coordiantes:

f = @(r, theta, phi) 4*exp(-r).*cos(theta).*sin(phi) 
[XX YY ZZ] = meshgrid(x_range, y_range, z_range) 
% R = sqrt(XX.^2 + YY.^2 + ZZ.^2) 
% Th = acos(XX./YY) 
% Phi = acos(ZZ./R) 
% This is faster. . . and significantly more correct. See the comments below. 
[Th,Phi,R] = cart2sph(XX,YY,ZZ) 
fvals = f(R, Th, Phi) 

我喜欢isosurface想象这样的3D数据。对于通过Z = 0的2D切片,您可以使用imagesc(fvals(:,:,N))contour(fvals(:,:,N))

+1

转换有点偏离,应该是:'Th = atan2(YY,XX); Phi = asin(ZZ./R);',但最好使用CART2SPH,因为它旨在避免数值问题 – Amro

+0

有没有一种更难以实现的方法? –

+0

@Amro:上面的代码如何修改为使用sph2cart()? –