Reputation: 68
I'm writing a game in java with the lwjgl. Basically i have two plans that i want to check if they intersect each other, like the image below.
I have the four points for each plane, can someone help me.
Upvotes: 2
Views: 1323
Reputation: 4411
The 2 planes do not intersect if they are parallel (and not the same plane).
Let p1
, p2
, p3
and p4
be your 4 points defining the plane and n=(a,b,c)
the normal vector computed as n=cross(p2-p1, p3-p1)
. The plane equation is
ax + by + cz + d = 0
where d=-dot(n,p1)
You have 2 planes
ax + by + cz + d = 0
a’x + b’y + c’z + d’ = 0
they are parallel (and not same) iff
a/a’ == b/b’ == c/c’ != d/d’
When you implement this predicate you have to check the divide by 0
Upvotes: 2
Reputation: 2497
I can't show this is enough, but I believe these three tests should be sufficient:
for two planes...
if there is no overlap in any of those three cases, the planes do not intersect. otherwise, the planes intersect.
let me know if you are not sure how to project onto an axis or calculate an overlap. also, let me know if these three tests are insufficient.
Edit 1:
Algorithm: You don't actually have to project, rather you can just find the maximum range. Let's do the x axis as an example. You find the minimum x value on plane 1 and the maximum x value on the plane 1. Next, you find the minimum x value on plane 2 and the maximum x value on plane 2. If their ranges overlap ( for example, [1 , 5] overlaps with [2 , 9] ), then there's overlap with the projections onto the x axis. Note that finding the range of x values might not be easy if edges of your plane segment aren't parallel with the x axis. If you're dealing with more complicated plane segments that don't have edges parallel to the axes, I can't really help then. You might have to use something else like matrices.
The test, by the way, is called a separating-axis test. I think the x, y, and z axis tests should be enough to test for plane segments intersecting.
Source: (Book) Game Physics Engine Development: How To Build A Robust Commercial-Grade Physics Engine For Your Game (Second Edition) by Ian Millington
Edit 2:
Actually, you'll need to check more axes.
Upvotes: 1