我有一个内径为r1,外半径为r2的空心圆柱体。该圆柱体从Z轴向X轴倾斜,然后绕Z轴旋转,然后沿X和Y方向平移。我还有一个X和Y值范围之间的立方体。然后我想计算空心圆柱体在立方体内的体积有多大。
%set variables
r1 = 0.9; r2 = 1.0;
z1 =-1.0; z2 = 1.0;
beta = pi/4; gamma = pi/8;
%create inner surface
[X,Y,Z] = cylinder(r1, 100);
%outer surface
[Xx,Yy,Zz] = cylinder(r2, 100);
%fix coordinates
X = [X,Xx]; Y = [Y,Yy]; Z = [Z,Zz];
Z(1,:) = z1; Z(2,:) = z2;
%elongate in first rotation direction
X = X/cos(beta);
%shift top and bottom accordingly
X(1,:) = X(1,:) + z2/tan(beta);
X(2,:) = X(2,:) + z1/tan(beta);
%also perform another rotation in XY plane
Xnu = X*cos(gamma) + -Y*sin(gamma);
Y = X*sin(gamma) + Y*cos(gamma);
X = Xnu;
%translation not included for this example
surf(X,Y,Z); axis equal
%try to make a cube from its nodes/corners
ix=-1;iy=-1;dx=0.5;dy=dx;
[X,Y,Z] = ndgrid( ix*dx+[-dx/2, dx/2] , iy*dy+[-dy/2, dy/2] , [z1, z2] );
X = reshape(X, 2, []);Y = reshape(Y, 2, []);Z = reshape(Z, 2, []);
%failed
surf(X,Y,Z); axis equal
空心圆筒似乎没问题。在边缘顶部没有'上限'。
立方体看起来不像立方体,但至少角落之间的体积应该是正确的。
我的问题是,如何获得这两种形状的交集,然后计算体积?
我实际上需要迭代这些管和立方体中的许多,但是一旦我将这个单个案例固定,那么它应该很容易。每个立方体代表来自实验的测量像素,每个空心圆柱体代表实验中的物理对象。在meshgrid本身上模拟这个时,我会非常快地遇到内存问题。