Matlab中的3D绘图有什么问题

时间:2021-11-10 06:47:12

I'm trying to create 3D plots in Matlab, and I have practically no experience. I'd really like to plot the figure described by these equations:

我想在Matlab中创建3D绘图,但我几乎没有经验。我很想画出这些方程描述的图形:

x = cos(u)*(2 + cos(v))
y = sin(u)*(2 + cos(v))
z = x^2 - y^2 + 2*x*y*tan^2(v)
-pi <= u <= pi, -pi <= v <= pi

Which plot originally should be like this

哪个情节本来应该是这样的

http://paulbourke.net/geometry/pseudocatenoid/1.jpg

http://paulbourke.net/geometry/pseudocatenoid/1.jpg

I've tried my best and came up with:

我尽了最大的努力,想到了:

% volume data
u = linspace(-pi,pi,40);
v = linspace(-pi,pi,40);
[u, v] = meshgrid(u, v); 
X =cos(u).*(2 + cos(v));
Y =sin(u).*(2 + cos(v));
Z =(X.^2)-(Y.^2)+(X.*Y.*2.*((tan(v)).^2));
surf(X,Y,Z,'FaceColor','none','EdgeColor','interp')

%shaded surface
colormap(jet)
camlight right

I get the following:

我得到以下:

Matlab中的3D绘图有什么问题

What's wrong?

怎么了?

1 个解决方案

#1


4  

There's actually nothing wrong with your graph. The reason why you see the graph like that is because the z axis is too large. The z values that actually define most of its shape are orders of magnitude smaller than the highest values seen in that graph... in the order of thousands. The reason why is because when the values of u and v are +/- pi/2, tan is undefined, which is why the heights are so high as you gravitate towards these angles.

实际上你的图没有任何问题。你看到这样的图是因为z轴太大了。实际上定义其大部分形状的z值的数量级小于该图中看到的最高值……成千上万的人。原因是当u和v的值是+/- /2时,tan是没有定义的,这就是为什么当你被这些角吸引时高度会很高。

One suggestion I have is to clip the z values if they get too large. Set some sort of threshold on the z values and clip them. Something like 100 for high positive values and -100 for large negative values. Also, adjust the viewing angle for a better view, and I would also recommend increasing the number of points so that the shading is better interpolated... something like 1000. For an even glossier effect, try changing the FaceColor attribute to interp rather than none.

我的一个建议是,如果z值太大,就剪掉它。在z值上设置某种阈值并将其修剪。100表示高正值,-100表示大负值。另外,调整视角以获得更好的视角,我也建议增加点的数量,以便更好地插入阴影…就像1000年。为了获得更均匀的模糊效果,请尝试将FaceColor属性更改为interp而不是none。

As such:

是这样的:

u = linspace(-pi,pi,1000); %// Define 1000 points per dimension
v = linspace(-pi,pi,1000);
[u, v] = meshgrid(u, v); 
X =cos(u).*(2 + cos(v));
Y =sin(u).*(2 + cos(v));
Z =(X.^2)-(Y.^2)+(2*X.*Y.*(tan(v).^2));
Z(Z <= -100) = -100; %// Enforce threshold
Z(Z >= 100) = 100;
surf(X,Y,Z,'FaceColor','interp','EdgeColor','interp')

%shaded surface
colormap(jet)
view(30,50); %// Change viewing angle
camlight right

I get this:

我得到了这个:

Matlab中的3D绘图有什么问题

#1


4  

There's actually nothing wrong with your graph. The reason why you see the graph like that is because the z axis is too large. The z values that actually define most of its shape are orders of magnitude smaller than the highest values seen in that graph... in the order of thousands. The reason why is because when the values of u and v are +/- pi/2, tan is undefined, which is why the heights are so high as you gravitate towards these angles.

实际上你的图没有任何问题。你看到这样的图是因为z轴太大了。实际上定义其大部分形状的z值的数量级小于该图中看到的最高值……成千上万的人。原因是当u和v的值是+/- /2时,tan是没有定义的,这就是为什么当你被这些角吸引时高度会很高。

One suggestion I have is to clip the z values if they get too large. Set some sort of threshold on the z values and clip them. Something like 100 for high positive values and -100 for large negative values. Also, adjust the viewing angle for a better view, and I would also recommend increasing the number of points so that the shading is better interpolated... something like 1000. For an even glossier effect, try changing the FaceColor attribute to interp rather than none.

我的一个建议是,如果z值太大,就剪掉它。在z值上设置某种阈值并将其修剪。100表示高正值,-100表示大负值。另外,调整视角以获得更好的视角,我也建议增加点的数量,以便更好地插入阴影…就像1000年。为了获得更均匀的模糊效果,请尝试将FaceColor属性更改为interp而不是none。

As such:

是这样的:

u = linspace(-pi,pi,1000); %// Define 1000 points per dimension
v = linspace(-pi,pi,1000);
[u, v] = meshgrid(u, v); 
X =cos(u).*(2 + cos(v));
Y =sin(u).*(2 + cos(v));
Z =(X.^2)-(Y.^2)+(2*X.*Y.*(tan(v).^2));
Z(Z <= -100) = -100; %// Enforce threshold
Z(Z >= 100) = 100;
surf(X,Y,Z,'FaceColor','interp','EdgeColor','interp')

%shaded surface
colormap(jet)
view(30,50); %// Change viewing angle
camlight right

I get this:

我得到了这个:

Matlab中的3D绘图有什么问题