Calculate volume of hollow tilted cylinder inside cube, without a grid

三世轮回 提交于 2019-12-11 18:30:09

问题


I have a hollow cylinder with inner radius r1 and outer radius r2. This cylinder is tilted from the Z axis towards the X axis, then rotated around the Z axis and then translated along X and along Y. I also have a cube between a range of X and Y values. I then want to calculate how large a volume of the hollow cylinder is inside the cube.

%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

The hollow cylinder seems OK. Just no 'cap' on the top of the edge.

The cube looks nothing like a cube, but at least the volume between the corners should be correct.

My question is, how do I get the intersection of these two shapes and then calculate the volume?

I actually need to iterate over many of these tubes and cubes, but once I have this single case fixed then it should be easy. Each cube represents a measured pixel from an experiment and each hollow cylinder a physical object that was in the experiment. When simulating this on a meshgrid itself I encounter memory issues very fast.

来源:https://stackoverflow.com/questions/50219554/calculate-volume-of-hollow-tilted-cylinder-inside-cube-without-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!