View Full Version : point intersection?

screwtape

04-14-2001, 09:49 PM

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?

Michael Steinberg

04-14-2001, 10:07 PM

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).]

ffish

04-15-2001, 10:57 PM

http://astronomy.swin.edu.au/pbourke/geometry/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).]

Michael Steinberg

04-16-2001, 03:36 AM

Has my code not been good?

screwtape

04-16-2001, 05:49 AM

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.

ffish

04-16-2001, 10:46 PM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.