Does anyone know how to plot a dome (aka half sphere) in MATLAB...or anyother programming language?
I need to plot a dome or half a sphere and be able to change the dim开发者_开发问答ensions of the dome. I figured MATLAB would be my best choice.
any suggestions?
THanks
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
take a look at surf
. the formula for a sphere is
x^2+y^2+z^2 = R^2
you may also need meshgrid
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);
I took a circle graph I made and adapted it to graph a dome. I can't test it but it should work since the circle worked fine.
I made this in JavaScript.
setVox
is just a function that will print a voxel on a 3D plane.
var rad = 1; //radius
for (var z = -(rad); z < 0; z++) {
r = Math.round(Math.sqrt(Math.pow(rad,2) - Math.pow(z,2)));
for (var x = -(r); x < r; x++) {
y = Math.round(Math.sqrt(Math.pow(r,2) - Math.pow(x,2)));
setVox(x,y,z);
setVox(x,-(y),z);
}
for (y = -(r); y < r; y++) {
x = Math.round(Math.sqrt(Math.pow(r,2) - Math.pow(y,2)));
setVox(x,y,z);
setVox(-(x),y,z);
}
}
精彩评论