Surface area of a plane within a cube
이전 댓글 표시
Hi,
I'm trying to solve a geometric problem. I have grid blocks which are represented as a cube. I also have rectangles on a plane that are orientated in and around the cube. I need to solve how much of the plane is within the cube.
If these planes were infinite, it would be easy. Since they are not infinite, it's not so trivial. Sometimes the corner points lie within the cube, sometimes outside the cube.
I've posted an example of one possible scenario.
This is a representation of a quartz vein in a block of rock. I'm simulating lots of these so the scenario can be varied.
So far, I check if all 4 points are within the bounds of the cube. If they are, the area is just calculated as is. If one point falls outside the cube (usually this is the case) then I project planes normal to x, normal to y and normal to z and this gives me the line of intersection. From here, I don't know how to solve for area outside the cube.
I'm really stuck on how to solve this issue. Some help would be great.

채택된 답변
추가 답변 (1개)
Mike Garrity
2014년 8월 28일
> Do you think I could adapt this code to work in 3D?
Sure, basically you just change the function Intersection so that it takes a plane equation and 3D point as input instead of a line equation and 2D point. Everything else stays exactly the same.
It would look something like this:
function t = Intersection(pt1,pt2,plane)
t = nan;
u = dot(pt1,plane(1:3)) - plane(4);
v = dot(pt2,plane(1:3)) - plane(4);
if (sign(u) ~= sign(v))
t = (0-u) / (v-u);
end
end
and here's an example of using it:
% define the 6 planes of a box
xrange = [-2 3];
yrange = [-2 4];
zrange = [-2 5];
planes = [1 0 0 xrange(2);
-1 0 0 -xrange(1);
0 1 0 yrange(2);
0 -1 0 -yrange(1);
0 0 1 zrange(2);
0 0 -1 -zrange(1)];
% intesect a bunch of random lines against the box
for i=1:1000
pt1 = rand(1,3);
pt2 = 10*randn(1,3);
t = zeros(1,6);
for i=1:6
t(i) = Intersection(pt1,pt2,planes(i,:));
end
startpt = pt1;
endpt = pt1+min(t)*(pt2-pt1);
line([startpt(1) endpt(1)],[startpt(2) endpt(2)],[startpt(3) endpt(3)])
end
view(3)
axis square
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!