function solidcube=CSGcube(xc,yc,zc,r,res)

if (res>50)
   res=50;
elseif (res<1)
   res=1;
end

res=1/res;
[x,y,z]=meshgrid(-1-res:res:1+res, ...
   -1-res:res:1+res, -1-res:res:1+res);

solidcube = 1 - 2*((abs(x-xc)<=r) & (abs(y-yc)<=r) & (abs(z-zc)<=r));


