How to define plane in 3d cube. Intersection point of segment with plane in 3d cube
4 次查看(过去 30 天)
显示 更早的评论
Hello!
I am trying to find intersection point with any planes of cube.
I wrote function of plane_line_intersect using this https://www.mathworks.com/matlabcentral/fileexchange/17751-straight-line-and-plane-intersection
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 个评论
采纳的回答
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!