我正在尝试绘制从 2D 函数 r=sin^2(theta) 获得的 3D 旋转曲面。2D 图是正确的(图 1),但 3D 曲面(在我看来)不正确(图 2)(澄清一下:我期望得到一个“甜甜圈”曲面,没有任何“尖峰”):
脚本如下(抱歉,评论是法语的):
theta=linspace(-pi,pi,200);
f=sin(theta).^2;
x=f.*cos(theta);
y=f.*sin(theta);
figure;
plot(x,y);
axis equal;
% Création des points pour la surface de révolution
u = linspace(-pi, pi, 200); % Angles de révolution
[U, T] = meshgrid(u, theta); % Création des grilles pour les coordonnées
% Coordonnées x, y et z pour la surface de révolution
X = R .* cos(U); % Coordonnée x après rotation
Y = R .* sin(U); % Coordonnée y après rotation
%Z = repmat(theta', 1, length(u)); % Coordonnée z reste alpha
% Tracé de la surface de révolution
figure;
surf(X, Y, Z);
xlabel('X'); ylabel('Y'); zlabel('Z');
title('Surface de révolution: r = sin^2(theta)');
shading interp;
你能帮助我了解这里发生了什么吗?
目前还不清楚您的错误是什么,因为您的代码不包含 的定义
R
(更不用说Z
被注释掉了),但我怀疑您计算了绕错误轴的旋转。如果您在 坐标系中开始绘制 2D 图x
,可能会更容易z
,因为在 3D 图中,垂直轴将是Z
:用 3D 坐标表示,并用
T
代替theta
(数学符号,不是代码):U
并执行绕轴的旋转Z
(再次强调,这不是八度代码):使用你的变量以八度书写,3D 图为: