简体   繁体   中英

Why not spherical plot? How to plot 3D-polar-plot in Matlab?

[r,t] = meshgrid(linspace(0,2*pi,361),linspace(0,pi,361));
[x,y]=pol2cart(sin(t)*cos(r),sin(t)*sin(r));
%[x,y]=pol2cart(r,t);
surf(x,y);

在此处输入图片说明

I played with this addon but trying to find an default function to for this. How can I do the 3D-polar-plot?

I am trying to help this guy to vizualise different integrals here .

There are several problems in your code:

  • You are already converting spherical coordinates to cartesian coordinates with the sin(theta)*cos(phi) and sin(theta)*sin(phi) bit. Why are you calling pol2cart on this (moreover, we're not working in polar coordinates!)?
  • As natan points out, there is no third dimension (ie z ) in your plot. For unity radius, r can be omitted in the spherical domain, where it is completely defined by theta and phi , but in the cartesian domain, you have all three x , y and z . The formula for z is z = cos(theta) (for unit radius).
  • You didn't read the documentation for surf , which says:

    surf(Z,C) plots the height of Z , a single-valued function defined over a geometrically rectangular grid, and uses matrix C , assumed to be the same size as Z , to color the surface.

    In other words, your surf(x,y) line merely plots the matrix x and colors it using y as a colormap.

Here's the above code with the mistakes fixed and plotted correctly:

[f,t] = meshgrid(linspace(0,2*pi,361),linspace(0,pi,361));
x = sin(t)*cos(f);
y = sin(t)*sin(f);
z = cos(t);
surf(x,y,z)

在此处输入图片说明

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