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 件のコメント

KSSV
KSSV 2020 年 12 月 6 日
Share the points....lets give a try.
Berk
Berk 2020 年 12 月 6 日
I add them into the post.

サインインしてコメントする。

回答 (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..
Matt J
Matt J 2020 年 12 月 6 日
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 ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

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