How to check 2D rectangle and 3D rectangular prism intersect with each other?

When there are 2D rectangle and 3D rectangular prism with their own orientations, how can I check if they intersect with each other in 3D space? I have 4 points for the rectangle and 8 points for the prism. Is there a built-in function I can use in MATLAB for this purpose? Two suitable rectangle and rectangular prism points are given as .mat file.

답변 (2개)

Matt J
Matt J 2020년 12월 6일
편집: Matt J 2020년 12월 6일
You can use intersectionHull() in this File Exchange submission,
load('rectangle.mat')
load('prism.mat')
S=intersectionHull('vert',prism,'vert',rectangle);
For the data you provided, there is indeed an intersection whose vertices are,
>> S.vert
ans =
649.7498 426.2143 507.2920
647.0217 430.5573 507.3727
655.9783 432.4427 512.9273
653.2502 436.7857 513.0080

댓글 수: 2

Berk
Berk 2020년 12월 6일
편집: Berk 2020년 12월 6일
Hello, thanks for help. Nevertheless, I can't use it in Simulink because it says "Function cellfun is not supported for code generation."
Actually, I don't need the intersection area, I just need to know if they intersect with each other. Maybe cellfun part might be used for finding intersection area and we can exclude that part..
If the sides of the prism and rectangle are always parallel/perpendicular to one another, there may be simpler ways.

댓글을 달려면 로그인하십시오.

Bruno Luong
Bruno Luong 2020년 12월 6일
편집: Bruno Luong 2020년 12월 6일
Quick and dirty code
load('prism.mat')
load('rectangle.mat')
% Normalize the coordinates
M = prism;
minM = min(M,[],1);
maxM = max(M,[],1);
dM = max(maxM-minM);
cfun = @(xyz) (xyz-(minM+maxM)/2)./dM;
M = [cfun(prism); -cfun(rectangle)]';
% Solve for common point
b = [0; 0; 0; 1; 1];
A = [M;
ones(1,8) zeros(1,4);
zeros(1,8) ones(1,4)];
w = lsqnonneg(A,b);
% Check if solution exists
if norm(A*w-b,inf)<1e-10
fprintf('intersected\n')
else
fprintf('not intersected\n')
end

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2020년 12월 5일

편집:

2020년 12월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by