当前位置:文档之家› 用matlab画球体

用matlab画球体

用matlab画球体
用matlab画球体

用matlab画球体

2007-05-18 18:05

ghostkid

[求助]如何画球体?附文件

所有球体半径为0.5,各球心坐标已知,请问如何将这些球体画出?用循环语句还是其他的?

比如球心坐标矩阵为posion=[0 0 0;1 1 1;0 1 0];其行向量为一个球心坐标,那么如何画出这三个球体来?我写了如下两个文件,运行后,视图坐标系不正确,请哪位帮忙看一下

ssphere.m

function ssphere(C,R)

% 画球面程序,R球面半径,C球心坐标

syms a b x y z;

x=R*cos(a)*sin(b)+C(1);

y=R*cos(a)*cos(b)+C(2);

z=R*sin(a)+C(3);

ezsurf(x,y,z,[0,2*pi,0,2*pi]);

axis equal;

test1.m

function test1

p=[0 0 0;1 1 1;0 1 0];

hold on;

for i=1:3

ssphere(p(i,:),0.5);

end

hold off;

2005-4-13 21:54 bzzz

Re:[求助]如何画球体?附文件

1、通过控制不同坐标轴大小位置控制球的大小

% first sphere

h(1) = axes('Position',[0 0 1 1]);

[Xs Ys Zs]=sphere(30); % create data for sphere surface

hs1 = surf(Xs, Ys, Zs); % create sphere

camlight(45,45);

lighting phong

hidden off

axis square

axis off

% second

h(2) = axes('Position',[0.1 0.1 0.5 0.5]);

[Xs Ys Zs]=sphere(20);

hs2 = surf(Xs, Ys, Zs);

camlight right;

lighting phong

hidden off

axis equal

axis off

2、另外一种方法对于生成的单位球体的数据进行扩展偏移来实现[x,y,z]=sphere(20);

surf(x,y,z);

hold on

x0=2+2*x;

y0=2+2*y;

z0=2+2*z;

surf(x0,y0,z0);

axis equal

相关主题
文本预览
相关文档 最新文档