This presentation is the property of its rightful owner.
1 / 7

3D plotting PowerPoint PPT Presentation

3D plotting. Recap 2D plotting. plot( x,y ): given sequence of x and y values, connects the dots (x( i ),y( i )) Exercise: Plot a circle >>t= linspace (0,2*pi,100); >>plot( cos (t),sin(t)). Plot3: Plotting curves in 3D.

3D plotting

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

3D plotting

Recap 2D plotting

• plot(x,y): given sequence of x and y values, connects the dots (x(i),y(i))

• Exercise: Plot a circle

>>t=linspace(0,2*pi,100);

>>plot(cos(t),sin(t))

Plot3: Plotting curves in 3D

• plot3(x,y,z): Given a sequence of x,y,z values connects the 3d dots (x(i),y(i),z(i))

• Exercise: plot a cylindrical spiral. For a cylindrical spiral

• x=cos(t), y=sin(t), z=t

>>t=linspace(0,8*pi,500);

>>x=cos(t);

>>y=sin(t);

>>z=t;

>>plot3(x,y,z,’o-’);

Exercise

• Plot a conical spiral. For a conical spiral

• x=t cos(t), y=t sin(t), z=t

surf: Plotting surfaces in 3D

• Load the elevation.mat from Assignment3

• surf(map) plots the function map(i,j) vsj,I

• Connects the dots by rectangular patches

• (j, i, h(i,j)) (j+1, i, h(i,j+1))

• (j, i+1, h(j,i+1) (j+1,i+1, h(i+1,j+1))

Plotting z(x,y) vsx,y

• Plot z=x^2+y^2 vsx,y

• [X,Y]=meshgrid(x,y) returns the cartesian product of the vectors x,y.

>>x=linspace(-5,5,100);

>>y=linspace(-3,3,50);

>>[X,Y]=meshgrid(x,y);

>>surf(X,Y,X.^2+Y.^2);

Exercise

• Plot the gaussian function. Its coordinates are given by

• z=exp(-(x^2+y^2)/2)

• Assume x,y lie between -5 and 5

• Plot a unit sphere. Its coordinates are given by the equation

• x=cos(t)*cos(p), y=cos(t)*sin(p), z=sin(t)

• where –pi/2<= t <=pi/2 and 0<=p<=2*pi