# How to determine if a 3D line segment intersects a side of a 3D rectangular prism?

9 views (last 30 days)
MS on 28 Sep 2022
Answered: Matt J on 29 Sep 2022
Hello,
I am trying to find a way to determine if a line segment drawn between two points in 3D space will intersect another 3D body (retangular prism) that is defined by regions using (x, y, z) vertices.
Is there a way to do this in Matlab?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Matt J on 28 Sep 2022
Edited: Matt J on 28 Sep 2022
You can use intersectionHull() in this FEX download,
##### 2 CommentsShowHide 1 older comment
Matt J on 28 Sep 2022
Edited: Matt J on 28 Sep 2022
No, you can specify both the line segment and the prism in terms of vertices if you wish, for example,
Vprism=dec2bin(0:2^3-1,2)-'0'+1 %vertices of prism
Vline=[0,0,0;3 3 3]; %vertices of line segment
I=intersectionHull('vert',Vprism,'vert',Vline); %compute intersection
>> I.vert
ans =
1.0000 1.0000 1.0000
2.0000 2.0000 2.0000

Sign in to comment.

### More Answers (1)

Matt J on 29 Sep 2022
You can also use Siddon's algorithm
which will compute the intersection between a ray and many prisms.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Categories

Find more on Map Display in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by