I need to plot multiple sphere and I was using the example code from mathwork help as follows -
我需要绘制多个球面,我使用的示例代码来自mathwork help如下
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?
我需要球体的半径不同。如何定义每个球的半径?
2 个解决方案
#1
9
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
:
[sphere]的帮助文件(http://www.mathworks.com.au/help/techdoc/ref/sphere.html)说它为一个单位球体或一个半径为1的球体生成坐标。要将半径为1的球的坐标改变为半径为r的球只需将它们乘以r:
[x,y,z] = sphere();
r = 5;
surf( r*x, r*y, r*z ) % sphere with radius 5 centred at (0,0,0)
#2
2
IMO, surf()
is not user friendly at all. The code surf(x+3,y-2,z) % sphere centered at (3,-2,0)
is counter-intuitive (surf(x-1,y+2,0)
is consistent with math).
在我看来,surf()根本不是用户友好的。代码surf(x+3,y-2,z) %球面居中于(3,-2,0)是反直觉的(surf(x-1,y+2,0)与数学是一致的)。
Anyway, I'd recommend you use ellipsoid()
instead. Since sphere is just a special case of ellipsoid, you can understand it easily and you don't have to deal with surf()
, look at http://www.mathworks.com/help/matlab/ref/ellipsoid.html
无论如何,我建议您使用椭圆体()。由于sphere只是一个特殊的椭球体,您可以很容易地理解它,而且您不必处理surf(),请查看http://www.mathworks.com/help/matlab/ref/椭圆体。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)');
#1
9
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
:
[sphere]的帮助文件(http://www.mathworks.com.au/help/techdoc/ref/sphere.html)说它为一个单位球体或一个半径为1的球体生成坐标。要将半径为1的球的坐标改变为半径为r的球只需将它们乘以r:
[x,y,z] = sphere();
r = 5;
surf( r*x, r*y, r*z ) % sphere with radius 5 centred at (0,0,0)
#2
2
IMO, surf()
is not user friendly at all. The code surf(x+3,y-2,z) % sphere centered at (3,-2,0)
is counter-intuitive (surf(x-1,y+2,0)
is consistent with math).
在我看来,surf()根本不是用户友好的。代码surf(x+3,y-2,z) %球面居中于(3,-2,0)是反直觉的(surf(x-1,y+2,0)与数学是一致的)。
Anyway, I'd recommend you use ellipsoid()
instead. Since sphere is just a special case of ellipsoid, you can understand it easily and you don't have to deal with surf()
, look at http://www.mathworks.com/help/matlab/ref/ellipsoid.html
无论如何,我建议您使用椭圆体()。由于sphere只是一个特殊的椭球体,您可以很容易地理解它,而且您不必处理surf(),请查看http://www.mathworks.com/help/matlab/ref/椭圆体。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)');