如何在高斯 3D 上绘制球体?

how to plot a sphere on top of Gaussian 3D?

我想在 3D 高斯上创建一个球体形状。

像这样:

为了绘制高斯分布,我写了 tihs:



% isotropic Gaussian parameters
n = 100; % resolution
s = 2; % width

x = linspace(-5,5,n);
[X,Y] = meshgrid(x);

gaus2d = exp( -(X.^2 + Y.^2 )/(2*s^2));

figure(1), clf
surf(x,x,gaus2d)

对于球体:


rotate3d on
hold on

[x1,y1,z1] = sphere;

% adjusting the radius of sphere 
x1 = x1*s;
y1 = y1*s;
z1 = z1*s;

surf(x1,y1,z1)

问题是:我不知道如何在高斯分布上移动球体。如何在Gaussain上转移球体?

您可以向球体的 z-values 添加一个常量,以便 'lift' 向上:

% isotropic Gaussian parameters
n = 100; % resolution
s = 2; % width

x = linspace(-5,5,n);
[X,Y] = meshgrid(x);

gaus2d = exp( -(X.^2 + Y.^2 )/(2*s^2));

figure(1), clf
surf(x,x,gaus2d)

rotate3d on
hold on

[x1,y1,z1] = sphere;

% adjusting the radius of sphere 
x1 = x1*s;
y1 = y1*s;
z1 = z1;

% add a constant to sphere, so that it is on top of gauss
addi = max(gaus2d(:)) - min(z1(:));
z1 = z1 + addi;

surf(x1,y1,z1)