2

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Miguel71
  • 68
  • 5
  • 2
    possible duplicate of [Finding the line along the the intersection of two planes](http://stackoverflow.com/questions/16025620/finding-the-line-along-the-the-intersection-of-two-planes) – genpfault Jul 23 '13 at 16:23

2 Answers2

2

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

a.lasram
  • 4,371
  • 1
  • 16
  • 24
1

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.

user2570465
  • 2,437
  • 2
  • 18
  • 22
  • yeah... I think i understand the concept, but how do i project onto an axis and calculate if the overlap. Thank you :) – Miguel71 Jul 23 '13 at 17:07
  • sorry, instead of x y and z axis, i believe it should be x-y, x-z and y-z planes. let me think about how to do those projections and overlaps and I'll let you know if I think of it. – user2570465 Jul 23 '13 at 17:20
  • actually never mind the planes. it's actually axes, when i referred back to a book, and I've added in what the book's method basically says. – user2570465 Jul 23 '13 at 19:27
  • That didnt work. That would work, but since the second plane is oblique that doesnt work. The oblique plane is considered like a cube. Thanks anyways. I will research on matrices as you say. – Miguel71 Jul 23 '13 at 19:45
  • yeah, i realized you needed more axes. i did box and box collisions, and possibly, you could treat the plane as a very thin box. that would require 15 axes to test. this is all assuming your planes are not infinite planes, right? – user2570465 Jul 23 '13 at 20:01
  • that sould slould work. Btw i think i know how to do it with a matrix, i'll post it when i'm done. – Miguel71 Jul 23 '13 at 21:33
  • I gave up, it is taking me too mush time and patience to do this. Thanks anyways! :) – Miguel71 Jul 23 '13 at 23:23