Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define radius while drawing sphere in Matlab?

I need to plot multiple sphere and I was using the example code from mathwork help as follows -

figure
[x,y,z] = sphere();
surf(x,y,z)  % sphere centered at origin
hold on
surf(x+3,y-2,z)  % sphere centered at (3,-2,0)
surf(x,y+1,z-3)  % sphere centered at (0,1,-3)
daspect([1 1 1])

I need the spheres to be different radius. How can I define radius for each of these spheres?

like image 636
Pow Avatar asked Dec 22 '22 00:12

Pow


1 Answers

The helpfile for [sphere] (http://www.mathworks.com.au/help/techdoc/ref/sphere.html) says that it generates coordinates for a unit sphere, or a sphere of radius 1. To change coordinates for a sphere of radius 1 to a sphere of radius r you just multiply them by r:

[x,y,z] = sphere();
r = 5;
surf( r*x, r*y, r*z ) % sphere with radius 5 centred at (0,0,0)    
like image 170
mathematical.coffee Avatar answered Jan 07 '23 22:01

mathematical.coffee