logo for matrixlab-examples.com
[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Matrixmania Blog
Contact
-> Sitemap <-
Matlab Books
Quick Matlab Guide
Matlab Tutorials
Matlab Examples
Matlab Flow Control
Boolean Algebra
Linear Algebra
Matlab 2D Plots
Matlab 3D Plots
Matlab GUI
Matlab Cookbook I
Matlab Cookbook II
Probability and Stats
Forums and Help
Relevant Links
Fun!
Your own Website?
Terms/Policies
leftimage for matrixlab-examples.com

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:

Matlab 3D sphere

Matlab 3D sphere, example 2

From '3D Plot Part 3' to home
From '3D Plot Part 3' to 3D Main


footer for matlab page