How to determine radius when drawing a sphere in matlab?

I need to build several areas, and I used the example code from the math 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 spheres of radius. How to determine the radius for each of these spheres?

+4
source share
2 answers

The help file for [ sphere ] ( http://www.mathworks.com.au/help/techdoc/ref/sphere.html ) says that it generates coordinates for a single sphere or sphere of radius 1. To change the coordinates for a sphere of radius 1 by a sphere of radius r , you simply 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) 
+9
source

IMO, surf() is not at all convenient. The code surf(x+3,y-2,z) % sphere centered at (3,-2,0) is counterintuitive ( surf(x-1,y+2,0) matches the math).

In any case, I would recommend using ellipsoid() instead. Since a sphere is just a special case of an ellipsoid, you can easily understand this and you do not need to deal with surf() , see http://www.mathworks.com/help/matlab/ref/ellipsoid.html

A simple example:

 r=5; [x,y,z]=ellipsoid(1,2,3,r,r,r,20); surf(x, y, z,'FaceColor','y', 'FaceAlpha', 0.2); axis equal; box on; xlabel('x-axis (m)'); ylabel('y-axis (m)'); zlabel('z-axis (m)'); 
+2
source

Source: https://habr.com/ru/post/1403002/


All Articles