필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
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
Matt J
Matt J 2022년 10월 30일
편집: Matt J 2022년 10월 30일
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.

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

채택된 답변

KSSV
KSSV 2022년 10월 28일
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

추가 답변 (1개)

Matt J
Matt J 2022년 10월 30일
편집: Matt J 2022년 10월 30일
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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by