using spherical coordinates, plot only the part of the sphere z =sqrt(9-x^2-y^2) that lies below the cone z = sqrt(x^2+y^2).

댓글 수: 2

Rik
Rik 2020년 12월 19일
Sounds like you need meshgrid (or ndgrid). What did you try?
Minh Nguyen
Minh Nguyen 2020년 12월 19일
theta = linspace(0,2*pi,30);
phi = linspace(0,pi/2,30);
[theta,phi] = meshgrid(theta,phi);
r=3;
[x,y,z] = sph2cart(theta,phi,r);
surf(x,y,z,'FaceAlpha',0.3)
hold on
x = -3:0.2:3 ;
y = -3:0.2:3 ;
[x,y] = meshgrid(x,y) ;
z = sqrt(x.^2+y.^2);
surf(x,y,z)
I use this code and i can plot two graph 2 z functions but my teacher asked me to plot only the graph below the cone and i dont know how to do it

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

 채택된 답변

Rik
Rik 2020년 12월 19일

0 개 추천

You have two surfaces:
theta = linspace(0,2*pi,30);
phi = linspace(0,pi/2,30);
[theta,phi] = meshgrid(theta,phi);
r = 3;
[x,y] = sph2cart(theta,phi,r);
z_sphere = sqrt(9-x.^2-y.^2);
z_cone = sqrt(x.^2+y.^2);
%remove all complex elements
z_sphere(imag(z_sphere)>eps)=NaN;z_sphere=real(z_sphere);
They share the same coordinate grid, so now we can do element-wise operations. You need to remove points where z_sphere is higher than z_cone. The easiest way to remove points without messing up the coordinate grid is by marking them with NaN:
z_sphere( z_sphere>z_cone ) = NaN;
surf(x,y,z_cone,'FaceAlpha',0.3),hold on % optional line
surf(x,y,z_sphere)
view(45,45)

추가 답변 (0개)

카테고리

태그

질문:

2020년 12월 19일

댓글:

2020년 12월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by