[英]Wrong 3D plot in Matlab
I'm trying to create 3D plots in Matlab, and I have practically no experience. 我正在尝试在Matlab中创建3D绘图,而我几乎没有经验。 I'd really like to draw the figure described by these equations: 我真的想画出这些方程描述的数字:
x = cos(u) sinh(t) / (cosh(t) - cos(u));
y = cos(u) sin(u) / (cosh(t) - cos(u));
z = sin(u);
where both u and t vary from -pi to pi. 其中u和t在-pi到pi之间变化。 This is what Paul Bourke calls Ghost Plane . 这就是Paul Bourke所说的幽灵飞机 。
clc
clear
a = -pi:.01:pi;
b = -pi:.01:pi;
[U,T] = meshgrid(a,b);
X = (cos(U).*sinh(T))./(cosh(T)-cos(U));
Y = (cos(U).*sin(U))./(cosh(T)-cos(U));
Z = sin(U);
figure
surf(X,Y,Z)
With the code, I get something... indescribable. 有了代码,我得到的东西......难以形容。 How do I plot the figure? 我如何绘制图形?
Your code is correct. 你的代码是正确的。 You just need to zoom in. 你只需要放大。
Some tips to make this more viewable: 一些提示,使其更具可见性:
Use less fine grids, by changing a = ...
and b = ...
to: linspace(-pi,pi,40);
使用较少的精细网格,通过将a = ...
和b = ...
更改为: linspace(-pi,pi,40);
Add this ,'FaceColor','none','EdgeColor','interp');
添加它,'FaceColor','none','EdgeColor','interp');
to the surf
command to only plot the lines and those in color. surf
命令只绘制线条和彩色线条。
Add this axis equal vis3d;
添加此axis equal vis3d;
after the surf
command, so the axis will have correct scaling and behave well while rotating. 在surf
命令之后,轴将具有正确的缩放并且在旋转时表现良好。
Add whitebg('black');
添加whitebg('black');
and grid off;
并grid off;
to make the background black. 使背景变黑。
Change to surf(X,Y,Z,-U,...);
改为surf(X,Y,Z,-U,...);
and add colormap('HSV');
并添加colormap('HSV');
if you want the same colors as in the original. 如果你想要与原版相同的颜色。
set(gca,'xtick',[]); set(gca,'xticklabel',[]); set(gca,'yticklabel',[]); set(gca,'ytick',[]);
to remove the axis ticks 删除轴刻度
You might want to use the cameratoolbar
to: Change the projection to perspective projection , zoom all the way out, move the camera in very close, to get nice perspective distortions. 您可能希望使用cameratoolbar
:将投影更改为透视投影 ,一直缩放,非常接近地移动相机,以获得良好的透视扭曲。
Voilà: 瞧:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.