
var x:Number = 1; x /= 0;
3D line segmentplane collision detection
I am working on a project in which I need to find the intersection point (if it exists) between a line segment and a plane. I can easily do this with 2 dimensions, but 3D is a little harder, and I haven't much 3D math.
Basically, what I have is a tilebased world that is managed as cubes, so all of the planes are either going to be flat to the front on the X/Y axes, or sideways along the Z/Y or Z/X axes.
I think the first thing I need is to be able to find the equation of a 3D line using only two 3D points, but I can't figure out how to do that!
Thanks in advance,
Zippy Dee

Originally Posted by ZippyDee
I haven't much 3D math.
I'll assume you're at least familiar with the dot product.
Basically, what I have is a tilebased world that is managed as cubes, so all of the planes are either going to be flat to the front on the X/Y axes, or sideways along the Z/Y or Z/X axes.
I don't understand what you're trying to say here, but you may have to adjust the following derivation for your problem. It might be simplified for your situation, or it may be that a plane/line segment intersection is not suitable by itself. Remember that planes extend infinitely in all directions orthogonal to their normals.
I think the first thing I need is to be able to find the equation of a 3D line using only two 3D points, but I can't figure out how to do that!
A line in 3D can be represented parametrically for points A and B and scalar t by the equation:
A line segment from point A to B can be represented by clamping "t" to the interval [0.0, 1.0].
The equation of a plane is also important for this problem. One representation of a plane is the equation:
...when using the dot product. X represents a POINT ON THE PLANE, n represents its normal and d is the distance from the origin in terms of n.
Since we're looking for the POINT ON THE PLANE where our line L(t) intersects the plane, we substitute L(t) into the X variable of our plane equation:
Solving for t gives:
Code:
d  n . A
t = 
n . B  n . A
The value t can then be checked for inclusion in the interval [0.0, 1.0], which is where our segment (as opposed to entire line) exists. If t is in [0.0, 1.0], then the point of intersection is L(t) where t is evaluated with the formula given above.
Keep in mind that it is possible for the denominator, n.B  n.A or n.(BA), to be 0. This will happen when the line segment is parallel to the plane, in which case no intersection occurs (but a divide by zero just might if you're not careful).

var x:Number = 1; x /= 0;
Basically, what I have is a tilebased world that is managed as cubes, so all of the planes are either going to be flat to the front on the X/Y axes, or sideways along the Z/Y or Z/X axes.
What I'm saying is that I'm using cubes. if each cube is facing straight forward, each face of the cube lies on a plane that goes either parallel or perpendicular to the screen. Therefore, if I'm looking at the front face of the cube, the Z of that plane is constant for each point on that plane. So all I have to do to define that face of the cube is give it minimum and maximum X values, and minimum and maximum Y values.
I also found the twopoint equation of a 3D line:
Code:
xx1 yy1 zz1
 =  = 
x2x1 y2y1 z2z1
Could I also use that and then solve for the unknowns?
Like...If I'm using that same face of the cube, I know the Z value of the collision, because Z is constant for all points on that plane. I just need to solve for X and Y of the line at that Z value. using the twopoint equation.
Does that make sense or is my logic completely wrong?
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
