dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: 3D line segment-plane collision detection

  1. #1
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549

    3D line segment-plane 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 tile-based 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

  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    15
    Quote Originally Posted by ZippyDee View Post
    I haven't much 3D math.
    I'll assume you're at least familiar with the dot product.
    Basically, what I have is a tile-based 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:
    Code:
    L(t) = A + t*(B-A)
    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:
    Code:
    (n . X) - d = 0
    ...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:
    Code:
    (L(t) . n) - d = 0
    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.(B-A), 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).

  3. #3
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    Basically, what I have is a tile-based 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 two-point equation of a 3D line:
    Code:
     x-x1       y-y1      z-z1
    ------- = ------- = -------
     x2-x1     y2-y1     z2-z1
    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 two-point 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center