How to write a Matlab function that draw a sphere?
The following Matlab function draws a sphere in the current figure:
function [X,Y,Z] = drawSphere(center, radius)
%drawSphere Draw a sphere
% center are the coordinates of the center [x,y,z]
% radius is the radius of the sphere
% The function returns the points of the sphere
[X,Y,Z] = sphere;
X = center(1) + X*radius
Y = center(2) + Y*radius
Z = center(3) + Z*radius
surf(X,Y,Z);
end
Here is an example of the use of the function:
drawSphere ([1,2,3],3);
axis square equal;
The previous script displays the following figure:
The following Matlab function draws a sphere in the current figure:
function [X,Y,Z] = drawSphere(center, radius)
%drawSphere Draw a sphere
% center are the coordinates of the center [x,y,z]
% radius is the radius of the sphere
% The function returns the points of the sphere
[X,Y,Z] = sphere;
X = center(1) + X*radius
Y = center(2) + Y*radius
Z = center(3) + Z*radius
surf(X,Y,Z);
end
Here is an example of the use of the function:
drawSphere ([1,2,3],3);
axis square equal;
The previous script displays the following figure:
# | ID | Query | URL | Count |
---|