在 MATLAB 中绘制不同高度的 3D 轴上的不同 2D 椭圆
Graph different 2D ellipses in 3D axes at different heights in MATLAB
我想绘制不同高度(z 坐标)的不同椭圆。
我的想法是编写以下代码:
z=0:1/64:3/8;
t=linspace(-pi,pi,25);
[t,z]=meshgrid(t,z);
x=cos(-t);
y=cos(-t-4*pi*z);
我希望 MATLAB 像这样阅读我的代码:
"Find x and y, and plot at the corresponding height (z). By doing so, join the points such that you'll form an ellipse at constant z".
我不确定我可以在这里使用哪种功能来执行此操作,希望有人告诉我是否存在可以完成这项工作或类似功能的功能。
如果您想知道,我想绘制给定两个反向传播光束的光的偏振图。
编辑:虽然这与问题 draw ellipse and ellipsoid in MATLAB 类似,但该问题并未解决在 3D 轴上绘制 2D 椭圆的问题,而这正是我正在尝试做的。
这可以通过删除 meshgrid
并仅使用普通的旧 for 循环来解决。
t = linspace(-pi,pi,25);
z = 0:1/64:3/8
f = figure;
hold on;
for i = 1:length(z)
x=cos(-t); y=cos(-t-4*pi*z(i));
plot3(x,y,z(i)*ones(length(z),1));
end
原始代码中的问题是您尝试一次构建所有椭圆,但每个椭圆仅依赖于单个 z 值,而不是整个 z 值数组。
当我运行这段代码时,它会产生以下情节:
我想绘制不同高度(z 坐标)的不同椭圆。
我的想法是编写以下代码:
z=0:1/64:3/8;
t=linspace(-pi,pi,25);
[t,z]=meshgrid(t,z);
x=cos(-t);
y=cos(-t-4*pi*z);
我希望 MATLAB 像这样阅读我的代码:
"Find x and y, and plot at the corresponding height (z). By doing so, join the points such that you'll form an ellipse at constant z".
我不确定我可以在这里使用哪种功能来执行此操作,希望有人告诉我是否存在可以完成这项工作或类似功能的功能。
如果您想知道,我想绘制给定两个反向传播光束的光的偏振图。
编辑:虽然这与问题 draw ellipse and ellipsoid in MATLAB 类似,但该问题并未解决在 3D 轴上绘制 2D 椭圆的问题,而这正是我正在尝试做的。
这可以通过删除 meshgrid
并仅使用普通的旧 for 循环来解决。
t = linspace(-pi,pi,25);
z = 0:1/64:3/8
f = figure;
hold on;
for i = 1:length(z)
x=cos(-t); y=cos(-t-4*pi*z(i));
plot3(x,y,z(i)*ones(length(z),1));
end
原始代码中的问题是您尝试一次构建所有椭圆,但每个椭圆仅依赖于单个 z 值,而不是整个 z 值数组。
当我运行这段代码时,它会产生以下情节: