pythonvectorsympyintersectionplane

3D line vector and plane Intersection


I have a 3D line vector given in the form of ai + bj + ck. I am calculating a plane using 3 points as given below.

from sympy import Point3D, Plane
def def_surface (a1,a2,a3):
    Flat1 = Plane(Point3D(a1), Point3D(a2), Point3D(a3)) 
    S = Flat1.equation()
    return S

I want to find the point P(x,y,z) where the line meets the plane.

P.S. Do I have to create a parametric equation after finding a point on a line? Or is there an easy way to get to the intersection point directly?

Assuming I have a point on a line S = (d,e,f), is there an easy way to find the intersection point?


Solution

  • There should be a slight adjustment to @Ulises Bussi's answer. Line = Line3D(p0,v0) is not giving the output we need. when p0 is a point and v0 is a vector, the Correct line equation will be given as,

    line = Line3D(p0,direction_ratio=v0)

    Hence the correct way of doing this would be:

    
    #plane Points
    a1 = Point3D (-5,15,-5)
    a2 = Point3D (5,15,-5)
    a3 = Point3D (5,15,5)
    #line Points
    p0 = Point3D (0,3,1) #point in line
    v0 = [0, 1 ,1] #line direction as vector
    
    #create plane and line
    plane = Plane(a1,a2,a3)
    
    line = Line3D(p0,direction_ratio=v0)
    
    
    print(f"plane equation: {plane.equation()}")
    print(f"line equation: {line.equation()}")
    
    #find intersection:
    
    intr = plane.intersection(line)
    
    intersection =np.array(intr[0],dtype=float)
    print(f"intersection: {intersection}")