# intersection between a plane and a line

#1

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]

#2

Hello Pixel!

This is actually a little harder than it seems, but not impossible ;>

from mathworld:

http://mathworld.wolfram.com/Line-PlaneIntersection.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]
addknot spl s #corner #line linePoint
addknot spl s #corner #line (linePoint+lineVector)
)

``````

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 (c-a) n) / (dot (b-a) n)
-- now we can calculate the intersection point.
r=a+t*(b-a)
-- 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]
addknot spl s #corner #line a
addknot spl s #corner #line b

``````

Hope this helps!

Josh.

#3

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
--------------------------------------------------------------------------------
fn planelineintersect c n a v= -- planelineintersect <plane_point> <plane_normal> <line_point> <line_vector>
(
b=a+v
r=a+(dot (c-a) n) / (dot (b-a) n)*(b-a)
)
/*
-- 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
*/

``````

#4

Fantastic, that’s exactly the answer I was hoping.

Many thanks again !

#5

no problem < :

#6

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?

#7

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à

#8

Yes, and a good idea!

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

let me know how it goes prettyPixel or if you found your own solution!

#9

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.

#10

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.