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 comentarios

Share the points....lets give a try.
I add them into the post.

Iniciar sesión para comentar.

Respuestas (2)

Matt J
Matt J el 6 de Dic. de 2020
Editada: Matt J el 6 de Dic. de 2020
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 comentarios

Berk
Berk el 6 de Dic. de 2020
Editada: Berk el 6 de Dic. de 2020
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.

Iniciar sesión para comentar.

Bruno Luong
Bruno Luong el 6 de Dic. de 2020
Editada: Bruno Luong el 6 de Dic. de 2020
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

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Dic. de 2020

Editada:

el 6 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by