cube = { [0,0,0,0; 0,0,1,1; 0,1,1,0], [1,1,1,1; 0,1,1,0; 0,0,1,1], ...
[0,1,1,0; 0,0,0,0; 0,0,1,1], [0,0,1,1; 1,1,1,1; 0,1,1,0], ...
[0,0,1,1; 0,1,1,0; 0,0,0,0], [0,1,1,0; 0,0,1,1; 1,1,1,1] }
% 3*5*8 box
box = { [0,0,0,0; 0,0,5,5; 0,3,3,0], [8,8,8,8; 0,5,5,0; 0,0,3,3], ...
[0,8,8,0; 0,0,0,0; 0,0,3,3], [0,0,8,8; 5,5,5,5; 0,3,3,0], ...
[0,0,8,8; 0,5,5,0; 0,0,0,0], [0,8,8,0; 0,0,5,5; 3,3,3,3]}
octahedron = { [1,0,0; 0,1,0; 0,0,1], [0,1,0; -1,0,0; 0,0,1], ...
[-1,0,0; 0,-1,0; 0,0,1], [0,-1,0; 1,0,0; 0,0,1], ...
[0,1,0; 1,0,0; 0,0,-1], [1,0,0; 0,-1,0; 0,0,-1], ...
[0,-1,0; -1,0,0; 0,0,-1], [-1,0,0; 0,1,0; 0,0,-1] }
% pyramid with square base (top half of octahedron)
pyramid = { [1,0,0; 0,1,0; 0,0,1], [0,1,0; -1,0,0; 0,0,1], ...
[-1,0,0; 0,-1,0; 0,0,1], [0,-1,0; 1,0,0; 0,0,1], ...
[1,0,-1,0; 0,-1,0,1; 0,0,0,0]}
% frustum (bottom half of pyramid expanded by 2)
frustum = { [2,0,0,1; 0,2,1,0; 0,0,1,1], [0,-2,-1,0; 2,0,0,1; 0,0,1,1], ...
[-2,0,0,-1; 0,-2,-1,0; 0,0,1,1], [0,2,1,0; -2,0,0,-1; 0,0,1,1] ...
[2,0,-2,0; 0,-2,-0,2; 0,0,0,0], [1,0,-1,0; 0,1,0,-1; 1,1,1,1]}
这样的.m文件怎么读入到function draw中并使用?
我在定义fuction之前load('polyhedra.m'),然后draw(cube),说cube没有定义
polyhedra;
function pprime=DrawRotatedPolyhedron(M,P)
poly=cell2mat(P);
n=size(P,2)
pprime=M*poly
end
这样octave里不行啊,
>> DrawRotatedPolyhedron(EulerRotation(pi/4,pi/4,0),cube)
error: `cube' undefined near line 5 column 50
error: evaluating argument list element number 2
你是在调用函数的时候使用数据啊?那样的话,在命令窗口里输入(function的前面的那句不要):
polyhedra;
DrawRotatedPolyhedron(EulerRotation(pi/4,pi/4,0),cube)
也就是不方便在写draw函数的时候调用这个polyhedra了?没有好办法?
追答你要搞清楚到底是在函数里面还是在外面调用数据,如果在外面,就像上面所说;如果要在函数里面调,就不要把它作为函数的参数传递,可以把函数改写:
function pprime=DrawRotatedPolyhedron(M)
polyhedra;
P = cube;
poly=cell2mat(P);
n=size(P,2)
pprime=M*poly
end
然后调用函数的时候用:
DrawRotatedPolyhedron(EulerRotation(pi/4,pi/4,0))