2016-10-20 31 views
0

我想繪製scilab中的以下對象。 Cone shaped object繪製scilab中的coneshaped對象

我可以分別繪製板和錐體,但我很難將單獨的零件放在一起。

有關如何做到這一點的任何想法?

這是我用來繪製圓錐的代碼

r = 2.0;

h = 4.0;

m = h/r; [R,A] = meshgrid(linspace(0,r,20),linspace(0,2 *%pi,41));其中,

X = R * cos(A);

Y = R * sin(A);

Z = m * R; (X,Y,Z)

mesh(X,Y,Z)

任何幫助將不勝感激。

回答

0

下面的代碼將做到這一點:

hr = 0.5 // height of the box 
wr = 4 // width of the box 
lr = 10 // length of the box 

hc = 3 // height of the cones 
rc = 2*0.45*min(wr,lr) // desired radius of the cone's base 

function xyz = getcoordinate(hr,lr,wr,hc,rc,axis) 
    // this function computes the faced used by plot3d to render the object 
    // hr: height of the box; Real 
    // wr: width of the box;Real 
    // lr: length of the box;Real 
    // hc: height of the cones;Real 
    // rc: desired radius of the cone's base;Real 
    // axis: which component we compute; String 


    // The 4 nodes of the top of the box 
    Bbl = 0.5*[-wr;-lr;hr] 
    Bbr = 0.5*[wr;-lr;hr] 
    Bul = 0.5*[-wr;lr;hr] 
    Bur = 0.5*[wr;lr;hr] 

    H = -[0;0;hr] 
    select axis 
    case 'x' then 
    i=1 
    case 'y' then 
    i=2 
    case 'z' then 
    i=3 
    else 
    error('Wrong compononent. ''x'',''y'' or ''z'' only') 
    end 
    // Box. We split each plane into triangles to concatenate with cones later. 
    xyz=[[Bbl(i)+H(i);Bbr(i)+H(i);Bur(i)+H(i)],.. 
    [Bur(i)+H(i);Bul(i)+H(i);Bbl(i)+H(i)],.. 
    [Bur(i);Bur(i)+H(i);Bbr(i)+H(i)],.. 
    [Bbr(i)+H(i);Bbr(i);Bur(i)],.. 
    [Bul(i);Bul(i)+H(i);Bur(i)+H(i)],.. 
    [Bur(i)+H(i);Bur(i);Bul(i)],.. 
    [Bbl(i);Bbr(i);Bbr(i)+H(i)],.. 
    [Bbr(i)+H(i);Bbl(i)+H(i);Bbl(i)],.. 
    [Bul(i);Bbl(i);Bbl(i)+H(i)],.. 
    [Bbl(i)+H(i);Bul(i)+H(i);Bul(i)],.. 
    [Bbl(i);Bur(i);Bbr(i)],.. 
    [Bur(i);Bbl(i);Bul(i)]] 

// cones. These are fac3d object, each facet is a triangle. 
// They are placed at 1-offset of both border and at the center. 
// radius is decreased if too big 
L = max(lr,wr) 
W = min(lr,wr) 
offset = 0.1 
rc = (1-offset)*min(min(rc,W/2),L/6) 
for k=1:3 // 3 cones 
    if wr < lr 
     Ct = [0;(k-2)*0.5*(L-2*rc/(1-offset));hc+0.5*hr] // top of the cone 
    else 
     Ct = [(k-2)*0.5*(L-2*rc/(1-offset));0;hc+0.5*hr] 
    end 
    Cb = Ct - [0;0;hc] // center of the cone's base 
    nmax = 20 // number of triangles 
    for n=1:nmax 
    P1 = Cb + rc*[cos((n-1)*2*%pi/nmax);sin((n-1)*2*%pi/nmax);0] 
    P2 = Cb + rc*[cos(n*2*%pi/nmax);sin(n*2*%pi/nmax);0] 
    xyz = [xyz,.. 
    [P1(i);Ct(i);P2(i)]] 
    end 
end 
endfunction 

xx = getcoordinate(hr,lr,wr,hc,rc,'x') 
yy = getcoordinate(hr,lr,wr,hc,rc,'y') 
zz = getcoordinate(hr,lr,wr,hc,rc,'z') 
plot3d(xx,yy,zz) 
set(gca(),'isoview','on') 

coneshaped object