很明显,这是球面的方程。为避免使用直角坐标表达会导致的多值问题,可用球面坐标生成数据,然后再转换到直角坐标。w未给定,任取一个值。
参考代码:
w = 5;
r = sqrt(w);
n = 30;
theta = (-n:2:n)/n * pi;
phi = (-n:2:n)/n * pi/2;
[theta,phi] = meshgrid(theta,phi);
cosphi = cos(phi); %cosphi(1) = 0; cosphi(n+1) = 0;
sintheta = sin(theta); %sintheta(1) = 0; sintheta(n+1) = 0;
x = r*cosphi.*cos(theta);
y = r*cosphi.*sintheta;
z = r*sin(phi);
surface(x,y,z)
view(3)
axis equal
grid on