Sei sulla pagina 1di 10

Grafico 3D

t = 0:pi/50:10*pi;
Three-Dimensional Line Plots plot3(exp(0.05*t).*sin(t),exp(0.05*t).*cos(t),t),
Lines in three-dimensional space can be plotted with
xlabel('x'),ylabel('y'),zlabel('z'),grid
the plot3 function. Its syntax is plot3(x,y,z). For example,
the following equations generate a three-dimensional
curve as the parameter t is varied over some range:

If we let t vary from t = 0 to t = 10π, the sine and cosine


functions will vary through five cycles, while the
absolute values of x and y become smaller as t
increases. This process results in the spiral curve
shown in Figure 5.4–1, which was produced with the
following session.
% Programa para representar una hélice en tres
dimensiones

clc; clear memory; clear command history; clear all;


t=0:0.1:30;
plot3(sin(t),cos(t),2*t)
title('Hélice')
xlabel('Seno(t)'); ylabel('Coseno(t)'),zlabel('2t')
Por ejemplo, si en la gráfica anterior queremos limitar
los ejes al doble de su valor actual, e introducir la
etiqueta "Gráfica en 3D" en las coordenadas x=0.25,
y=0.25, z=20:

% Programa para representar una hélice en tres


dimensiones

clc; clear memory; clear command history; clear all;


t=0:0.1:30;
plot3(sin(t),cos(t),2*t)
title('Hélice')
xlabel('Seno (t)'); ylabel('Coseno (t)'),zlabel ('2 t')
axis([-2 2 -2 2 0 120]);
text(0.25,0.25,100,'GRAFICA EN 3D')
grid
% Programa para representar gráfico tipo malla

clc; clear memory; clear command history; clear all;

[X,Y]=meshgrid(-7.5:0.5:7.5);
Z=sin(sqrt(X.^2+Y^2))./(sqrt(X.^2+Y.^2)+eps);

% Le sumaremos esp al denominador para no dividir por cero


% (eps es la cantidad más pequeña que maneja MATLAB, mayor que cero)

subplot(2,2,1)
mesh(X,Y,Z)
title('Comando mesh')
subplot(2,2,2)
meshz(X,Y,Z)
title('Comando meshz')
subplot(2,2,3)
meshc(X,Y,Z)
title('Comando meshc')
[x y] = meshgrid(-2.1:0.15:2.1, -6:0.15:6);
% x - y-grids different
u = 80 * y.^2 .* exp(-x.^2 - 0.3*y.^2);
contour(u)
theta=pi/3; r=linspace(0,1,30); phi=linspace(0,2*pi,30);
[r,phi]=meshgrid(r,phi); x=r.*cos(phi)*sin(theta);
y=r.*sin(phi)*sin(theta); z=r*cos(theta); mesh(x,y,z) xlabel('x');
ylabel('y'); zlabel('z') title('Superficie cónica')
r=1*ones(30,1); phi=linspace(0,2*pi,30); [r,phi]=meshgrid(r,phi);
x=r.*cos(phi); y=r.*sin(phi); z=repmat(linspace(0,2,30),30,1);
surfl(x,y,z); shading interp colormap(gray); axis equal
xlabel('x'); ylabel('y'); zlabel('z') title('Superficie cilíndrica')
%esfera
R=1; phi=linspace(0,pi,30); theta=linspace(0,2*pi,40);
[phi,theta]=meshgrid(phi,theta); x=R*sin(phi).*cos(theta);
y=R*sin(phi).*sin(theta); z=R*cos(phi); h1=mesh(x,y,z);
set(h1,'EdgeColor',[0.6,0.6,0.6]);
%probar una superficie esférica semitransparente
%set(h1,'EdgeColor',[0.6,0.6,0.6],'EdgeAlpha',0.5,'FaceAlpha',0.5)
%paralelo theta=pi/3; phi=0:0.1:2*pi+0.1; x=sin(theta)*cos(phi);
y=sin(theta)*sin(phi); z=cos(theta)*ones(1,length(x)); h1=line(x,y,z);
set(h1,'Color',[.7,0,0],'LineWidth',1.5)
%meridiano de referencia
phi=0; theta=-pi:0.1:pi; x=sin(theta)*cos(phi); y=sin(theta)*sin(phi);
z=cos(theta); h1=line(x,y,z); set(h1,'Color',[0,0,.7],'LineWidth',1)
%meridiano
phi=-pi/6; theta=-pi:0.1:pi; x=sin(theta)*cos(phi); y=sin(theta)*sin(phi);
z=cos(theta); h1=line(x,y,z); set(h1,'Color',[.7,0,0],'LineWidth',1.5) axis equal
view(60,10) hold off xlabel('x'); ylabel('y'); zlabel('z') title('Superficie esférica')

Potrebbero piacerti anche