我正在尝试使用 Matlab 生成此图。内置的椭球函数令人困惑。对于这个问题,我有两个变量(宽度和长度)和一个恒定的高度。
为了让它变得非常简单,我想表明当我们接近尖端时宽度正在变化,但高度是恒定的。w,x,h 是图中显示的变量。
如果有人可以提供帮助,我将不胜感激。
我正在尝试使用 Matlab 生成此图。内置的椭球函数令人困惑。对于这个问题,我有两个变量(宽度和长度)和一个恒定的高度。
为了让它变得非常简单,我想表明当我们接近尖端时宽度正在变化,但高度是恒定的。w,x,h 是图中显示的变量。
如果有人可以提供帮助,我将不胜感激。
我想,下面的代码让你走得很远。查看示例输出:
我添加了足够多的评论,您应该可以从这里获取它...
% plot ellipsoid in 3D
% height and width of ellipsoid:
e_h = 10;
e_w = 3;
% position where the "quivers" (arrows) go:
q_offset = 2; % distance from axis
q_scale = 0.5; % multiplier to give parabola some size
q_spacing = 0.5; % distance between arrows
q_height = 2.5; % height above XY plane where arrows are drawn
N = 1000; % number of points for drawing
theta = linspace(0, 2*pi, N); % parameter to help drawing ellipse
zerov = zeros(1, N); % array of zeros that I will need
% coordinates of main ellipse:
x = e_w * sin(theta);
y = zeros(size(x));
z = e_h * cos(theta);
% plot main ellipse:
figure;
plot3(x, y, z)
% secondary plot
y2 = q_scale*(e_w.^2 - x.^2) + 2; % offset parabola - what your plot looked like...
hold on
plot3(x, y2, zerov+q_height); % plotting the parabola in the XY plane at height
axis equal % make the plot dimensions isotropic
% add quivers
q_base = -e_w:q_spacing:e_w; % x coordinate; y and z are fixed
q_length = (e_w.^2 - q_base.^2)*q_scale; % length of quiver - just an equation I chose
q0 = zeros(size(q_base)); % another vector I will need multiple times
q1 = ones(size(q_base)); % ditto
% plot the arrows: the "-1" argument means "don't scale"
quiver3(q_base, q0+q_offset, q_height*q1, q0, q_length, q0, -1)