简体   繁体   中英

How to use Matlab to draw these 3D shapes?

I am trying to use Matlab to create these 3D shapes for illustration purpose (Please see the image below). I think surf is the function I should use; however, haven't got a clue what are the functions I should use to represent these shapes. Anyone can suggest an example please? Thanks.

在此处输入图片说明

A.

Edit 1:

Thanks for the replies from Trogdor and PetrH.

Currently, I am trying to plot a shape that is more sharp. For example, z = x.^2 + y.^2; can plot a normal cup shape. However, I want to plot something like the subplot on the right hand side shown below. Tried several different function but not working. Thanks for any tips!

在此处输入图片说明

Edit 2:

Use z = x.^2 -4*x+ y.^2-4*y; can make the shape more flat. Still haven't got a method to make it sharp.

在此处输入图片说明

You can use meshgrid to generate x and y matrices to plug into az function. For example:

[x,y] = meshgrid(-10:10);
z = x.^2 + y.^2;
figure;surf(z);

will generate a plot similar to the first figure. The second figure is the same thing, but defining z as:

z = y.^2;

And so on.

EDIT: The third figure is a saddle, found using

z = x.^2 - y.^2;

Thanks to PetrH for pointing that out.

The 4th and fifth are inversions of the first two.

z = -x.^2;
z = -x.^2 - y.^2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM