如何在 MATLAB 中使用点生成圆顶
How to generate a dome by using points in MATLAB
我正在尝试使用 x、y、z 值生成半椭圆圆顶形状。在我下面的代码中,我定义了 x、y、z 值,但我无法将这些值分配给球体。
我该如何解决这个问题?
clc
x = [65 55.2125 50.8267 46.7398 42.9232 39.3476 35.9815 32.7882 29.7175 26.6833 23.4690 18.7605];
y = x;
z = [0.0,0.9,2.7,5.2,8.2,11.8,15.8,20.3,25.2,30.7,37.1,47.5]; % max height of dome is 47.5
[x,y,z] = sphere(20);
x = x(12:end,:);
y = y(12:end,:);
z = z(12:end,:);
r = 65; % radius of the dome
surf(r.*x,r.*y,r.*z);
axis equal;
您可以通过将 NaN
s 分配给 x
和 y
的适当元素来移除球体的下半部分:
[x,y,z] = sphere(20);
I = (z<0);
x(I) = NaN;
y(I) = NaN;
surf(x,y,z)
使用椭圆体的参数方程会更简单或至少更优雅。
% semi axis parameters
a = 65; % x-axis
b = 65; % y-axis
c = 47.5; % z-axis
%% Parametrisation
%
% To reach each point of the ellipsoide we need two angle:
% phi ∈ [0,2]
% theta ∈ [0, ]
%
% But since we only need half of an ellipsoide we can set
% theta ∈ [0,/2]
[theta,phi] = ndgrid(linspace(0,pi/2,50),linspace(0,2*pi,50));
x = a*sin(theta).*cos(phi);
y = b*sin(theta).*sin(phi);
z = c*cos(theta);
%plot
surf(x,y,z)
axis equal
结果:
我正在尝试使用 x、y、z 值生成半椭圆圆顶形状。在我下面的代码中,我定义了 x、y、z 值,但我无法将这些值分配给球体。
我该如何解决这个问题?
clc
x = [65 55.2125 50.8267 46.7398 42.9232 39.3476 35.9815 32.7882 29.7175 26.6833 23.4690 18.7605];
y = x;
z = [0.0,0.9,2.7,5.2,8.2,11.8,15.8,20.3,25.2,30.7,37.1,47.5]; % max height of dome is 47.5
[x,y,z] = sphere(20);
x = x(12:end,:);
y = y(12:end,:);
z = z(12:end,:);
r = 65; % radius of the dome
surf(r.*x,r.*y,r.*z);
axis equal;
您可以通过将 NaN
s 分配给 x
和 y
的适当元素来移除球体的下半部分:
[x,y,z] = sphere(20);
I = (z<0);
x(I) = NaN;
y(I) = NaN;
surf(x,y,z)
使用椭圆体的参数方程会更简单或至少更优雅。
% semi axis parameters
a = 65; % x-axis
b = 65; % y-axis
c = 47.5; % z-axis
%% Parametrisation
%
% To reach each point of the ellipsoide we need two angle:
% phi ∈ [0,2]
% theta ∈ [0, ]
%
% But since we only need half of an ellipsoide we can set
% theta ∈ [0,/2]
[theta,phi] = ndgrid(linspace(0,pi/2,50),linspace(0,2*pi,50));
x = a*sin(theta).*cos(phi);
y = b*sin(theta).*sin(phi);
z = c*cos(theta);
%plot
surf(x,y,z)
axis equal
结果: