在scilab中绘制coneshaped对象

时间:2016-10-20 07:38:10

标签: plot scilab

我试图用scilab绘制下面的对象。 Cone shaped object

我可以分别绘制盘子和锥体,但是我很难将各个部分组合在一起。

关于如何做到这一点的任何想法?

这是我用来绘制圆锥的代码

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)

非常感谢任何帮助。

1 个答案:

答案 0 :(得分: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