I'm trying to plot a 3D surface of revolution obtained from the 2D function r=sin^2(theta). The 2D plot is correct (Figure 1), but the 3D surface is (in my opinion) not correct (Figure 2) (to clarify: I'd expect a "doughnut" surface, without any "spike"):
The script is (sorry for the comments in French):
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;
Could you please help me to understand what is happening here?
It's not completely clear what your error is, because your code doesn't contain the definition of R
(not to mention
that Z
is commented out), but I suspect you computed the rotation around the wrong axis. It might be easier if you
started the 2D plot in x
, z
coordinates, since in the 3D plot the vertical axis will be Z
:
theta=linspace(-pi,pi,200);
f=sin(theta).^2;
x=f.*cos(theta);
z=f.*sin(theta);
plot(x,z);
axis equal;
Written with the 3D coordinates and with T
instead of theta
(mathematical notation, not code):
X = sin(T)^2 * cos(T)
Y = 0
Z = sin(T)^3
and perform the rotation of U
around Z
axis (again, this is not octave code):
X = X * cos(U) - Y * sin(U) = sin(T)^2 * cos(T) * cos(U)
Y = X * sin(U) + Y * cos(U) = sin(T)^2 * cos(T) * sin(U)
Z = Z = sin(T)^3
Writing this in octave, using your variables, the 3D plot is:
theta=linspace(-pi,pi,200);
u = linspace(-pi, pi, 200);
[U, T] = meshgrid(u, theta);
X = sin(T).^2 .* cos(T) .* cos(U)
Y = sin(T).^2 .* cos(T) .* sin(U)
Z = sin(T).^3
surf(X, Y, Z);
axis equal;
xlabel('X'); ylabel('Y'); zlabel('Z');