tags:

views:

60

answers:

3

I need to plot a dome or half a sphere and be able to change the dimensions of the dome. I figured MATLAB would be my best choice.

any suggestions?

THanks

+1  A: 

take a look at surf. the formula for a sphere is

x^2+y^2+z^2 = R^2

you may also need meshgrid

second
The help for `surf` even has an example of drawing a sphere.
Ben Voigt
+1  A: 

Here's a starting point:

R = 7;
[X,Y] = meshgrid(-10:.1:10);
Z = sqrt(R.^2 - X.^2 - Y.^2);
Z(imag(Z) ~= 0) = 0;
mesh(X,Y,Z);
Ben Voigt
+3  A: 

The SPHERE function generates x, y, and z coordinates for a spherical surface. You just have to remove points corresponding to the bottom of the sphere to make a dome. For example:

[x,y,z] = sphere;      %# Makes a 21-by-21 point sphere
x = x(11:end,:);       %# Keep top 11 x points
y = y(11:end,:);       %# Keep top 11 y points
z = z(11:end,:);       %# Keep top 11 z points
r = 3;                 %# A radius value
surf(r.*x,r.*y,r.*z);  %# Plot the surface
axis equal;            %# Make the scaling on the x, y, and z axes equal
gnovice
how do you remove points
dewalla
@dewalla: I updated my answer to show how you can index into x, y, and z to get the points you want.
gnovice
Is there a way to make it a dome rather than a sphere? (aka the x y and z components are not all the same?
dewalla
@dewalla: Maybe I'm misunderstanding what you mean by "dome". The code above cuts the sphere in half and plots this hemisphere. If you're wanting to deform the hemisphere to flatten or stretch it in certain directions, then you can scale each variable (`x`, `y`, and `z`) by a different amount instead of the same amount `r`.
gnovice

related questions