- Why are you using 3D axis to plot an ellipse?
- How do you want the plot to behave in 3-D?
- What equation are you using to plot the ellipse?
- What does your expected plot look like?
Hey so I am trying to code an ellipse and I was confused about the placement of my plot. Should it be before the for loop or after?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
% Given Variables
a= 20; % Meters (m)
b=10; % Meters (m)
h=18; % Meters (m)
n=5;
t=0:0.01 : 2*pi*n;
% Calculations
r= (((a*b)./(sqrt(b*cos (t)).^2))+(a*sin(t).^2)) ;
x= (r .*cos(t));
y= (r.*sin(t));
z= ((h*t)./(2*pi*n)) ;
% Plotting plot 3
figure(1)
plot3 (x,y,z)
title('A ellispe')
xlabel('x')
ylabel('y')
zlabel('z')
grid on
% Loop for N=3
N=3;
for k=1:1:N
a2= 20*k; % Meters (m)
b2= 10*k;% Meters (m)
h2=18*k;% in Meters (m)
n=5;
t=0:0.01:2*pi*n;
r2= (((a2*b2)./(sqrt (b2*cos (t)).^2))+ (a2*sin(t).^2)) ;
x2= (r2.*cos (t));
y2= (r2.*sin(t));
z2= ((h2*t)./ (2*pi*n)) ;
% Define Meshgrid
[xx,yy]= meshgrid(x2, y2);
zz=xx.^2-yy.^2;
% Plotting
figure(2)
plot3 (x2 ,y2 , z2)
mesh(xx, yy, zz)
title(' A ellispe function')
xlabel( 'x=r*cos (t) ')
ylabel('y=r*sin(t)')
zlabel('= (h*t)./ (2*pi*n) ')
grid on
hold on
end
1 comentario
Eshan Patel
el 2 de Nov. de 2022
In order for the community to help, could you please give more information about the plot you are expecting? You can include the following information:
Respuestas (1)
Alan Stevens
el 2 de Nov. de 2022
Something like this? (I've commented out your meshgrid commands as they just confuse the plot and I'm not at all clear why they are there - you can easily reinstate them if you wish).
% Given Variables
a= 20; % Meters (m)
b=10; % Meters (m)
h=18; % Meters (m)
n=5;
t=0:0.01:2*pi*n;
% Calculations
r= a*b./sqrt( (b*cos(t)).^2+(a*sin(t)).^2 ) ;
x= (r.*cos(t));
y= (r.*sin(t));
z= ((h*t)./(2*pi*n)) ;
% Plotting plot 3
figure(1)
plot3 (x,y,z)
title('An ellipse')
xlabel('x')
ylabel('y')
zlabel('z')
grid on
% Loop for N=3
figure(2)
N=3;
for k=1:N
a2= 20*k; % Meters (m)
b2= 10*k;% Meters (m)
h2=18*k;% in Meters (m)
r2= a2*b2./sqrt( (b2*cos(t)).^2+(a2*sin(t)).^2 ) ;
x2= (r2.*cos (t));
y2= (r2.*sin(t));
z2= ((h2*t)./ (2*pi*n)) ;
% Define Meshgrid
% [xx,yy]= meshgrid(x2, y2);
% zz=xx.^2-yy.^2;
% Plotting
plot3 (x2 ,y2 , z2)
% mesh(xx, yy, zz)
title(' A ellipse function')
xlabel( 'x=r*cos (t) ')
ylabel('y=r*sin(t)')
zlabel('= (h*t)./ (2*pi*n) ')
grid on
hold on
end
0 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!