 |
3D plot –
Part 3
In this part, we demonstrate the use of the function 'sphere'. We are
going to draw a unit sphere centered at the origin and generated by
matrices x, y and z, of size 31 x 31 each.
Just as an excercise, we also add a line going from the center of the
sphere to one of the corners in the figure (within the 3D plot).
Example:
% cleans the
workspace
clc; clear; close all
% returns the
coordinates of a sphere in three
% matrices
that are (n+1)-by-(n+1) in size
[x, y, z] = sphere(30);
plot3(x,y,z)
% keeps the
proportions in place and writes appropriate info.
axis('square')
title('Transparent Sphere')
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
% keeps the
above sphere in order to superimpose a line
hold on
% the line
goes from (-1, 1, 1) to (0, 0, 0)
a = -1 : .1 : 0;
b = 1 : -.1 : 0;
c = b;
plot3(a, b, c)
% draws the
sphere in another format and in another figure
% see what
happens if we don't use the axis('square') instruction
figure
mesh(x,y,z)
hold on
plot3(a, b, c)
And the resulting figures are:
From
'3D Plot Part 3' to
home
From
'3D Plot
Part 3' to 3D Main


|
|