Advertisement

Intersection between a line and a plane..

Started by July 12, 2000 01:43 PM
3 comments, last by monkeyman 24 years, 5 months ago
If anybody can help me with this I would greatly appreciate it.. I need to find the intersection between a line and and a plane for polygon splitting purposes..the way I do it now is: *Find the distance from the first point to the plane.. *Find the distance from the second point to to the plane.. *Get a percentage from the 2 distances.. *Add the vector of the line multiplied by this percentage to the first point. At right angles this works beautifully, but the closer the line gets to being parallel with the plane, floating point imprecision renders the distances(which I use for my percentage) more and more inaccurate..in most cases it''s not too obvious, but I know there must be a better way..does anybody know the definitive FDA approved formula for finding the intersection between a line and a plane? "Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
Got it now thanks
"Like all good things, it starts with a monkey.."
Advertisement
So now you''ve got it ... well ... I''m waiting ... aren''t you going to post the result here so others wont have to ask the same question?

wytraven@kik.net
There is nothing real outside our perception of reality. Is there?
[email=wytraven@kik.net]wytraven@kik.net[/email]There is nothing real outside our perception of reality. Is there?
Will post explicit code tomorrow, check back..glad to see I''m not the only one

"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
Here''s the data that we need to work with:

float lp1x //starting point of the line segment
float lp1y //
float lp1z //

float lp2x //end point of the line segment
float lp2y //
float lp2z //

float spx //a point known to be on the plane
float spy //any point of the polygon will do
float spz //

float nx //normal vector of the plane
float ny //
float nz //

//here''s my old way of doing things:
//warning:I modified alot of this to make it easier
//to understand so forgive me for any typos..this should
//still work, though, I didn''t hack it too much

float dist1 = ((lp1x-spx)*nx+(lp1y-spy)*ny+(lp1z-spz)*nz);
float dist2 = ((lp2x-spx)*nx+(lp2y-spy)*ny+(lp2z-spz)*nz);
float percent = (((dist1+dist2)*(dist1/(dist1+dist2)))/sqrt(
((lp2x-lp1x)*(lp2x-lp1x))+
((lp2y-lp1y)*(lp2y-lp1y))+
((lp2z-lp1z)*(lp2z-lp1z))
));
float intx = lp2x-((lp2x-lp1x)*percent);//here''s
float inty = lp2y-((lp2y-lp1y)*percent);//our
float intz = lp2z-((lp2z-lp1z)*percent);//intersection

//now that I have the official formula, it would look
//like this..haven''t tested it yet
float percent = -(((lp1x*nx)+(lp1y*ny)+(lp1z*nz))-(spx*nx+spy*ny+spz*nz))/(((lp2x-lp1x)*nx)+((lp2y-lp1y)*ny)+((lp2z-lp1z)*nz));
float intx = lp2x-((lp2x-lp1x)*percent);//here''s
float inty = lp2y-((lp2y-lp1y)*percent);//our
float intz = lp2z-((lp2z-lp1z)*percent);//intersection

as you can see the second is much better, get to avoid the
dreaded sqrt..as I said, I haven''t officially tested the
new way and I really chopped up the original so feel free
to slam me if either of these don''t work..I can guarantee
that the first one works, if anyone wants the original code
email me..the reason I changed alot of it was because I was
pulling the data out of surface and vector structs and I wanted
to demonstrate with discrete variables, so yes, I know there''s
alot of duplicate math going on with the line vector..


"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."

This topic is closed to new replies.

Advertisement