hemisphere

Create hemisphere
105 Downloads
Updated 20 Feb 2023

View License

Adaption of the default Matlab sphere function to create hemispheres.
Syntax
[X,Y,Z] = hemisphere
[X,Y,Z] = hemisphere(n)
hemisphere(___)
hemisphere(ax,___)
Description
[X,Y,Z] = hemisphere returns the x-, y-, and z- coordinates of a hemisphere without drawing it. The returned hemisphere has a radius equal to 1 and consists of 20-by-20 faces.
The function returns the x-, y-, and z- coordinates as three 21-by-21 matrices.
To draw the hemisphere using the returned coordinates, use the surf or mesh functions.
[X,Y,Z] = hemisphere(n) returns the x-, y-, and z- coordinates of a hemisphere with a radius equal to 1 and n-by-n faces. The function returns the x-, y-, and z- coordinates as three (n+1)-by-(n+1) matrices.
hemisphere(___) plots the hemisphere without returning the coordinates. Use this syntax with any of the input arguments in previous syntaxes.
hemisphere(ax,___) plots into the axes specified by ax instead of the current axes. Specify the axes as the first input argument.
Examples
Display Unit Hemisphere
hemisphere
axis equal
Specify Hemisphere Radius and Location
Specify the radius and location of a hemisphere by modifying the returned X, Y, and Z coordinates.
Define X, Y, and Z as coordinates of a unit hemisphere.
[X,Y,Z] = hemisphere;
Plot the unit hemisphere centered at the origin.
surf(X,Y,Z)
axis equal
Define X2, Y2, and Z2 as coordinates of a hemisphere with a radius of 5 by multiplying the coordinates of the unit hemisphere. Plot the second hemisphere, centering it at (5,-5,0).
hold on
r = 5;
X2 = X * r;
Y2 = Y * r;
Z2 = Z * r;
surf(X2+5,Y2-5,Z2)
Display Sphere with Different Numbers of Faces
Call the tiledlayout function to create a 2-by-2 tiled chart layout. Call the nexttile function to create the axes. Then, use the hemisphere function to plot three hemispheres with different numbers of faces into different tiles of the chart by specifying the axes.
tiledlayout(2,2);
ax1 = nexttile;
hemisphere(ax1);
axis equal
title('20-by-20 faces (Default)')
ax2 = nexttile;
hemisphere(ax2,50)
axis equal
title('50-by-50 faces')
ax3 = nexttile;
hemisphere(ax3,100)
axis equal
title('100-by-100 faces')
Create Hemispherical Cylinder
Combine hemisphere with cylinder to create a hemispherical cylinder or cylinder with rounded ends.
Plot the cylinder.
[X1,Y1,Z1] = cylinder;
surf(X1,Y1,Z1); % plot cylinder
axis equal
Add the top and bottom hemispherical ends.
[X2,Y2,Z2] = hemisphere;
hold on
surf(X2,Y2,Z2+1); % plot top hemisphere
surf(X2,Y2,-Z2); % plot bottom hemisphere
See Also

Cite As

Nick Van Oosterwyck (2024). hemisphere (https://www.mathworks.com/matlabcentral/fileexchange/125090-hemisphere), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with R2006a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.4

add See Also

1.0.3

typo

1.0.2

add examples

1.0.1

update description

1.0.0