Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: point intersection?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    16

    point intersection?

    Its been a couple of years since I had my advanced calc, so I don't remember this, and I've been trying to figure it out but this is easier...

    okay, I have points A and B, and a plane in between them, how do I calculate the point along the vector defined from A to B that intersects the plane?

    If you can give me general formulas I would be most appreciative.

    For example lets say we have A=(-5, 2, -15); C=(15,4,-25) and a plane defined by x=5;

    Obviously by hand we can see that it intersects at B=(5, 3, -20), but what is the general formula?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    Re: point intersection?

    Code :
     
    int LinePlaneIntersect( CVector& a, CVector& b, CPlane& plane, CVector& result ){
            double quot, t;
            plane.normal.Normalize();
            t    = (plane.place-a)*plane.normal;
            quot = b*plane.normal;	
     
            if( DOUBLE_EQ( quot, 0.0 ) ) {
                 if( DOUBLE_EQ( t, 0.0 ) )
                        return LPI_INSIDE; 
                 else return LPI_PARALLEL;	
            }
            t    = t/quot;
            result = a+b*t;
            return LPI_CUT;
    }
    a is the place vector of the line, b the direction vector.
    DOUBLE_EQ checks wether two doubles are about the same (with a little delta due to imprecision).
    Returns LPI_INSIDE if the line is inside the plane. LPI_PARALLEL if the line is parallel to the plane. LPI_CUT otherwise.

    I have a vector class, that's why I can simply calculate with these vectors. The theory stays the same however, even if you haven't it (yeah... sorry.)

    [This message has been edited by Michael Steinberg (edited 04-15-2001).]
    - Michael Steinberg

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: point intersection?

    http://astronomy.swin.edu.au/pbourke...try/planeline/

    No code, but 2 ways to tackle the problem. It's also simple to turn into code.

    Thanks again Paul Bourke! Great site. Always helps me when I'm too lazy to pick up a textbook.

    [This message has been edited by ffish (edited 04-16-2001).]

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    Re: point intersection?

    Has my code not been good?
    - Michael Steinberg

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    16

    Re: point intersection?

    actually I feel stupid that I didn't come back and close the discussion; about 5 minutes after I posted that I figured it out, so though I didn't end up using your code, I'm sure that its good, however given my own datatypes and such and the fact that I figured it out before I had a chance to read your post, I didn't end up using them. Sorry, but thanks.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: point intersection?

    Your code was good Michael. I just posted a reference that I use fairly often for lots of different geometry related problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •