View Full Version : intersection between a plane and a line
prettyPixel 11012005, 09:29 AM Does somebody know the formula to calculate the intersection between a plane and a line?
The plane is defined by its normal and some point of this plane.
The line is defined by a vector and some point of this line.
example:
planeNormal=[0,0,1]
planePoint=[1,2,3]
lineVector=[0,0,1]
linePoint=[2,4,9]
Thanks in advance.


jman
11012005, 11:40 AM
Hello Pixel!
This is actually a little harder than it seems, but not impossible ;>
from mathworld:
http://mathworld.wolfram.com/LinePlaneIntersection.html
but, luckily for us Max comes with all sorts of funky things for finding this kind of stuff out so why do we need to get too complicated!! :
(
planeNormal=[0,0,1]
planePoint=[1,2,3]
lineVector=[0,0,1]
linePoint=[2,4,9]
p=plane pos:planepoint dir:planenormal  create a plane for our intersection
converttomesh p  turn it into a mesh for our intersectray
r=ray linepoint linevector  cast the ray
i=(intersectray p r)  find the intersection
if i!=undefined then h=point pos:i.pos dir:i.dir  if there is an intersection, place a marker!
 make a spline between our two points
spl=splineshape pos:[0,0,0]
s=addnewspline spl
addknot spl s #corner #line linePoint
addknot spl s #corner #line (linePoint+lineVector)
updateshape spl
)
This is only going to work in certain circumstances, for example the lpane is ony so large! so maybe maths is a better way to go after all:
n=[0,0,1]  planeNormal
c=[1,2,3]  planePoint
v=[0,0,1]  lineVector
a=[2,4,9]  linePoint
b=a+v  turn our line pos and vector into a second point b
 t is the missing part of our equation, and is calculated by dividing the dot product of
 the plane point and the start point, and the end point and the start point.
t=(dot (ca) n) / (dot (ba) n)
 now we can calculate the intersection point.
r=a+t*(ba)
 the intersection point!
p=point pos:r
 make a plane and a shape to test visually:
 the plane:
p=plane pos:c dir:n
 the vector:
spl=splineshape pos:[0,0,0]
s=addnewspline spl
addknot spl s #corner #line a
addknot spl s #corner #line b
updateshape spl
Hope this helps!
Josh.
jman
11012005, 11:54 AM
or as a function! :>

 Find the intersection of a vector on a plane
 version 1.0
 www.joshuanewman.net (http://www.joshuanewman.net/)
 last updated 27/10/05
 copyright 2005

fn planelineintersect c n a v=  planelineintersect <plane_point> <plane_normal> <line_point> <line_vector>
(
b=a+v
r=a+(dot (ca) n) / (dot (ba) n)*(ba)
)
/*
 for example!
p=plane pos:[1,2,3] dir:[0,0,1]
r=planelineintersect p.pos p.dir [2,4,9] [0,0,1]
pnt=point pos:r
*/
J¬
prettyPixel
11012005, 12:10 PM
Fantastic, that's exactly the answer I was hoping.
And your comments help me to understand how that does work.
Many thanks again !
jman
11012005, 12:16 PM
no problem < :
J¬
prettyPixel
11012005, 12:52 PM
Hello Joshua
Is there a mean to discover if the vector is parallel to the plane directly in the mathematical function ?
The function could return the value 0 if there is no collision and 1 if there is an infinity of solutions.
Is it possible without calculating indefinite or infinite values?
prettyPixel
11012005, 01:32 PM
Oh. I just found the solution: It's linked to the 2 dot values.
If the second dot is equal at zero then the vector is parallel.
If the first dot is also equal at zero then the vecteur is included in the plane.
Et voilą ;)
jman
11012005, 03:59 PM
Hello Joshua
Is there a mean to discover if the vector is parallel to the plane directly in the mathematical function ?
The function could return the value 0 if there is no collision and 1 if there is an infinity of solutions.
Is it possible without calculating indefinite or infinite values?
Yes, and a good idea!
Oh. I just found the solution: It's linked to the 2 dot values.
If the second dot is equal at zero then the vector is parallel.
If the first dot is also equal at zero then the vecteur is included in the plane.
Et voilą ;)
I never tested it that far, but yes, true. I came across a problem in the function, that I think is caused by the rounding problem in Max. I seem to remebmer someone discussing on the discreet board a while back. Took me a little while to figure it out, I thought It might be calculating the DOT product with non normailzed vectors but I'm pretty sure everything is normalized.
I've incorporated a tolerance that says that the result of the DOT can be between 0.0000000754 and 0.0000000754 which makes it accurate to less than .01 degrees
If the error is somewhere else then please someone let me know (vectors smectors!).
www.joshuanewman.net/scripts/download/JN_intersect_planeFN01.1.zip (http://www.joshuanewman.net/scripts/download/JN_intersect_planeFN01.1.zip)
let me know how it goes prettyPixel or if you found your own solution!
J¬
prettyPixel
11022005, 12:41 AM
For me your function is perfect now.
I will use it soon in a real use. Then I could say you more about it...
Thank you very much Joshua.
CGTalk Moderation
11022005, 12:41 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.