I have two 4D shapes: a polytope composed of two triangles with each side connected to the corresponding side on the other triangle (think triangular prism, but not necessarily straight) and a line segment.
I don't need to know where they intersect, just whether they intersect or not. How can I check for this?
Your convex polytope is delimited by a number of hyperplanes, of equation ax+by+cz+dw+e = 0
. Considering a point inside the polytope, you can adjust the signs so that all inside points verify ax+by+cz+dw+e ≥ 0
for all hyperplanes.
Now a line segment will have parametric equations like
x = (1-t)x'+tx''
y = (1-t)y'+ty''
z = (1-t)z'+tz''
w = (1-t)w'+tw''
and you can find the meeting points of the line P'P''
with every hyperplane. You will discard those such that t
is not in [0,1]
, and discard those that are not in the positive side of the other hyperplanes. If you find some meeting point that fits, then the polytope and the segment do intersect.