Miguel71
Miguel71

Reputation: 68

Detect collision between two 3d planes

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.

enter image description here

I have the four points for each plane, can someone help me.

Upvotes: 2

Views: 1323

Answers (2)

a.lasram
a.lasram

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

user2570465
user2570465

Reputation: 2497

I can't show this is enough, but I believe these three tests should be sufficient:

for two planes...

  1. project each plane onto the x axis, check if there is any overlap
  2. project each plane onto the y axis, check if there is any overlap
  3. project each plane onto the z axis, check if there is any overlap

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

Related Questions