MATLAB: Plotting a spherical segment

3d plot

Hi, I need to plot a spherical segment (blue region of the sphere in the attached picture).
Do you have any suggestions?
Gilles

Best Answer

clc; clear all ;
[X,Y,Z] = sphere(200) ;
surf(X,Y,Z) ;
r = 1; b = 0.9 ; h = 1 ;
%%Get radius
R = sqrt(X.^2+Y.^2) ;
X1 = X ; Y1 = Y ; Z1 = Z ;
X1(Z<r/2) = NaN ; Y1(Z<r/2) = NaN ; Z1(Z<r/2) = NaN ;
X1(Z>b) = NaN ; Y1(Z>b) = NaN ; Z1(Z>b) = NaN ;
surf(X1,Y1,Z1) ;
axis equal
% shading interp ;