问题
I know about the function sph2cart
, but I feel like I must be using it wrong. In a Calculus textbook, I saw that this following spherical equation:
ρ = 1 + 1/5*sin(6θ)*sin(5Φ)
produces something that looks like this:
![](https://www.eimg.top/images/2020/03/21/8e3444cd45b4ec80e2a6790ea6e09d77.png)
I wanted to reproduce this in a Matlab graph, so I wrote the following code
[q,t] = meshgrid(linspace(0,pi,100),linspace(0,2*pi,100));
rho = 1+1/5*sin(6*t)*sin(5*q);
[x,y,z] = sph2cart(t,q,rho);
surf(x,y,z)
axis square, axis equal
And I got the following graph:
![](https://www.eimg.top/images/2020/03/21/3db8549b75bcbc0a6b330066e209d158.jpg)
Why is this happening? Why am I not getting the bumpy sphere my calc textbook shows?
回答1:
There are two problems:
You need .* rather than * between your sin(6*t) and sin(5*q) since you want per element multiplication not matrix multiplication.
You want q to run from 0-PI and t to run from 0-2PI
This code produces the result you're looking for.
[q,t] = meshgrid(linspace(0,2*pi,100),linspace(0,pi,100));
rho = 1+(1/5*sin(6*t).*sin(5*q));
[x,y,z] = sph2cart(t,q,rho);
surf(x,y,z)
axis square, axis equal
![](https://www.eimg.top/images/2020/03/21/61506e0fd8163097b075f866bb61545f.png)
来源:https://stackoverflow.com/questions/30089707/i-need-help-graphing-a-spherical-equation-in-cartesian-coordinates-in-matlab