Ak_Yaka
Ak_Yaka

Reputation: 31

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?

Upvotes: 1

Views: 2902

Answers (2)

Ulises Bussi
Ulises Bussi

Reputation: 1725

When using sympy its important to conservate the whole object to find the intersection and not just the equation.

Suposing you have the direction and one point in the line you could do this:


from sympy import Plane, Line3D #Point3D it's not needed here

#plane Points
a1 = [1,0,0]
a2 = [0,1,0]
a3 = [0,0,1]
#line Points
p0 = [0,0,0] #point in line
v0 = [1,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)

print(f"intersection: {intr}")

Outputs

plane equation: x + y + z - 1
line equation: (-x + y, -x + z)
intersection: [Point3D(1/3, 1/3, 1/3)]

Upvotes: 2

Ak_Yaka
Ak_Yaka

Reputation: 31

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}")

Upvotes: 2

Related Questions