How to plot a surf-plot of semi sphere in matlab using sphere equation

8 views (last 30 days)
Hi, I am trying to plot a semi sphere (with out using sphere command in Matlab) using the sphere equation ((x-a)/r)^2+((y-b)/r)^2+((z-a)/r)^2 = 1; But I am confused hot to choose x, y, z. I tried with the below code but I seem to do some thing wrong somewhere...could any one provide me with a better way to do it
x = 0:1:640;
y = 0:1:480;
[x y] = meshgrid(x,y);
z = -((x-320).^2)/(25)-((y-240).^2)/(25)-1;
z(z<0)=0;
figure();
meshc(z);
My end result should look as shown below

Accepted Answer

darova
darova on 18 Apr 2019
Take closer look on your equation
Must be:
If you have complex values use:
z1 = real(z); % instead of z(z<0)=0

More Answers (0)

Community Treasure Hunt

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

Start Hunting!