Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Line, plane intersection Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Ken

September 07, 1999, 05:39 PM

Hi.
How can i find intersection of a line with a plane,
given plane equation and 2 end-points ?
And, where can i fine information on binary space patitioning ?

 
Kurt Miller

September 07, 1999, 06:18 PM



Ken wrote:
>>How can i find intersection of a line with a plane,
>>given plane equation and 2 end-points ?
>>And, where can i fine information on binary space patitioning ?

In line with what Jaap said in response to the previous question on
this message board, do people actually read any documents or articles
before asking questions? :) That's what they're there for. Boards like
these are here to help out when you have specific problems implementing
something that isn't overly documented or for comments/ideas/feedback on
something that you're working on. Answers to both of your questions can
very easily be found on this site and various others. For example, search the
resource section for "bsp".

-kurt

 
Raven

September 07, 1999, 06:20 PM

First, i'll give you a math overhaul, then i'll give you the actual working example:

You find the parameter t of the line at the plane by the following equation:

t=(q-DP1)/(DP2-DP1)

where:

t -> is the line parameter at the intersection
q -> is the free component in the plane equation(see below)
DP1 -> is the dot product of the beginning of the line with the plane normal
DP2 -> is the dot product of the end of the line with the plane normal

Explanation of equations:

a line segment can be defined analytically as:

P1+(P2-P1)t=0

where:

P1, P2 -> the beginning and end points of the segment, respectively
t -> the parameter(a number from 0 to 1)

a plane is defined by:

Ax+By+Cz+q=0, or in vector math: Np+q=0

where:

N -> the normal vector. N=(A, B, C)
q -> the free component(see above)

now, to put all this to work(pseudo-code, but this works, it's cut/paste-ed right out of my engine with dereferencing and all):

t=(Plane->q-DotProd1)/(DotProd2-DotProd1);

Vert1->x=Vert1->x+(Vert2->x-Vert1->x)*t;
Vert1->y=Vert1->y+(Vert2->y-Vert1->y)*t;
Vert1->z=Vert1->z+(Vert2->z-Vert1->z)*t;

so much for coordinates, but you ask why didn't we just plug in the line equation into the plane equation? this is why:

// Color
Vert1->r=Vert1->r+(Vert2->r-Vert1->r)*t;
Vert1->g=Vert1->g+(Vert2->g-Vert1->g)*t;
Vert1->b=Vert1->b+(Vert2->b-Vert1->b)*t;
Vert1->a=Vert1->a+(Vert2->a-Vert1->a)*t;

// Texture
Vert1->TexCoords.s=Vert1->TexCoords.s+(Vert2->TexCoords.s-Vert1->TexCoords.s)*t;
Vert1->TexCoords.t=Vert1->TexCoords.t+(Vert2->TexCoords.t-Vert1->TexCoords.t)*t;

And it magically clips a line and all of its parameters to a plane! Now, if this doesn't work then make sure your t is between 0 and 1.

As to BSP-trees, here's a link to get a nice crash course in them:

http://24.112.84.101/tutorials/index.shtml

This has several tutorials on interesting stuff(like radiosity), and the guy even wrote a column for flipcode. Overall this gives a great crashcourse in these areas, but you still need to do some research to actually get a live engine out of it. Like a person smarter than me said(and there's a lot of those, ohoh!) no pain no gain:)

 
Ken

September 08, 1999, 12:46 AM

Thanks a lot Raven, that really helped.


 
This thread contains 4 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.