How to define plane in 3d cube. Intersection point of segment with plane in 3d cube

4 Ansichten (letzte 30 Tage)
Hello!
I am trying to find intersection point with any planes of cube.
And using this function I was able to find intersection point. But before it I need to identify with which plane my segment will be intersected
And also I wrote function which will first check all planes for intersection and then I will call function plane_line_intersect
I am confused about how to write and organize all plane coordinates (p0, p1, p2, p3) of each plane in one function check_planes Should it be after I have attached picture and my code.
Thank you in advance for any help
Here is my code
function [I] = check_planes(x0,x1)
% Plane1 of cube
p0 = [0 3 3];
p1 = [0 0 3];
p2 = [0 3 0];
p3 = [0 0 0];
% Plane 2 of cube
p0 = [0 0 3];
p1 = [3 0 3];
p2 = [0 0 0];
p3 = [3 0 0];
% Plane 3 of cube
p0 = [3 0 3];
p1 = [3 3 3];
p2 = [3 0 0];
p3 = [3 3 0];
% Plane 4 of cube
p0 = [3 3 3];
p1 = [0 3 3];
p2 = [3 3 0];
p3 = [0 3 0];
% Plane 5 of cube
p0 = [0 3 0];
p1 = [3 3 0];
p2 = [0 0 0];
p3 = [3 0 0];
% Plane 6 of cube
p0 = [0 3 3];
p1 = [3 3 3];
p2 = [0 0 3];
p3 = [3 0 3];
for i=1:6
[I, check] = plane_line_intersect(p0, p1, p2, p3, V0, x0, x1);
if check == 1
return
end
end
end
  1 Kommentar
Matt J
Matt J am 30 Okt. 2022
Bearbeitet: Matt J am 30 Okt. 2022
If you are doing this for the purposes of tomographic forward projection, it's a bad idea to do it in Matlab. There are publicly available, well-optimized forward projector libraries that will do it, e.g.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 28 Okt. 2022
You define p0, p1, p2 and p3 as matrix arrays.
function [I] = check_planes(x0,x1)
p0 = zeros(1,3,6) ;
p1 = zeros(1,3,6) ;
p2 = zeros(1,3,6) ;
p3 = zeros(1,3,6) ;
% Plane1 of cube
p0(1,:,1) = [0 3 3];
p1(1,:,1) = [0 0 3];
p2(1,:,1) = [0 3 0];
p3(1,:,1) = [0 0 0];
% Plane 2 of cube
p0(1,:,2) = [0 0 3];
p1(1,:,2) = [3 0 3];
p2(1,:,2) = [0 0 0];
p3(1,:,2) = [3 0 0];
% Plane 3 of cube
p0(1,:,3) = [3 0 3];
p1(1,:,3) = [3 3 3];
p2(1,:,3) = [3 0 0];
p3(1,:,3) = [3 3 0];
% Plane 4 of cube
p0(1,:,4) = [3 3 3];
p1(1,:,4) = [0 3 3];
p2(1,:,4) = [3 3 0];
p3(1,:,4) = [0 3 0];
% Plane 5 of cube
p0(1,:,5) = [0 3 0];
p1(1,:,5) = [3 3 0];
p2(1,:,5) = [0 0 0];
p3(1,:,5) = [3 0 0];
% Plane 6 of cube
p0(1,:,6) = [0 3 3];
p1(1,:,6) = [3 3 3];
p2(1,:,6) = [0 0 3];
p3(1,:,6) = [3 0 3];
for i=1:6
[I, check] = plane_line_intersect(p0(1,:,i), p1(1,:,i), p2(1,:,i), p3(1,:,i), V0, x0, x1);
if check == 1
fprintf('%d plane\n',i)
return
end
end
end

Weitere Antworten (1)

Matt J
Matt J am 30 Okt. 2022
Bearbeitet: Matt J am 30 Okt. 2022
Use intersectionHull() and addBounds from this FEX download:
lb=[0 0 0]; %upper and lower bounds of cube
ub=[1 1 1];
Pt1=-[0.5 0.5 0.5]; %line segment end points
Pt2=+[2 2 2];
[A,b] =addBounds([],[],[],[],lb,ub);
S=intersectionHull('vert',[Pt1;Pt2],...
'lcon', A,b ); %intersection of line segment and cube
>> S.vert
ans =
0 0.0000 0.0000
1.0000 1.0000 1.0000

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by