How to plot sphere in sphere coordinates?

조회 수: 4 (최근 30일)
Niklas Kurz
Niklas Kurz 2020년 10월 18일
댓글: Bruno Luong 2020년 10월 21일
I'm just trying to plot known sphere coordinates:
function sphere(r)
phi = linspace(0,2*pi);
theta = linspace(0,pi);
x = r*cos(phi).*sin(theta);
y = r*sin(phi).*sin(theta);
z = r*cos(theta);
plot3(x,y,z)
end
However this isn't doing the trick. What have I mathematically confounded?

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 10월 19일
Your problem is not with conversion or plotting, but defining the coordinates that you want...
[phi,theta] = meshgrid(linspace(0,2*pi),linspace(0,pi));
Also if you didn't know:
  댓글 수: 2
Niklas Kurz
Niklas Kurz 2020년 10월 21일
yea, but I wanted to go through the rough way ;)
You could have said additionally that I need to swap plot3(x,y,z) with mesh(x,y,z), but all in all you've been nudging me in the right direction. Thx
J. Alex Lee
J. Alex Lee 2020년 10월 21일
sure thing. if you decide you don't want the rough way and you haven't seen it, check
[X,Y,Z] = r*sphere(n)
mesh(X,Y,Z)
% surf(X,Y,Z) % filled in faces
Also check out

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2020년 10월 21일
function sphere(r)
phi = linspace(0,2*pi);
theta = linspace(0,pi).'; % first change
x = r*cos(phi).*sin(theta);
y = r*sin(phi).*sin(theta);
z = r*cos(theta)+0*phi; % second change, make z same-size 2d array as x and y
plot3(x,y,z);
end
  댓글 수: 3
Niklas Kurz
Niklas Kurz 2020년 10월 21일
What a hoot! Just one thing: what does
.'
stand for?
Bruno Luong
Bruno Luong 2020년 10월 21일
Click on .'

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by