Finding the point of intersection between two lines

90 Views Asked by At

I have this code below and I am trying to find the intersection between L12 and L13 by using the matrix determinant. I have all the formulae set up but instead of [1,1,1] and [1,1,1] I would like to put in the coefficients of L12 and L13 respectively but have tried lots but am not sure how?

from sympy import *

(x, y, z) = symbols('x,y,z')


def getLine(P, Q):
    M = Matrix([P, Q, [x, y, z]])
    L = Poly(simplify(M.det()), x, y, z)
    a = L.coeff_monomial(x)
    b = L.coeff_monomial(y)
    c = L.coeff_monomial(z)
    if c != 0:
        L = L / c
    if c == 0 and b != 0:
        L = L / b
    if c == 0 and b == 0:
        L = (x, x)
    return simplify(L)


P1 = [-1, 6, 1]
P2 = [8, -24, 1]
P3 = [-24, 152, 27]
Q1 = (4, 4, 1)
Q2 = [5632, 16256, -1331]
Q3 = [24, 152, -27]

L12 = getLine(P1, Q2)
L13 = getLine(P1, Q3)
L23 = getLine(P2, Q3)
L21 = getLine(P2, Q1)
L31 = getLine(P3, Q1)
L32 = getLine(P3, Q2)

(i, j, k) = symbols('i,j,k')
M = Matrix([[1, 1, 1], [1, 1, 1], [i, j, k]])
determinant = simplify(M.det())
print determinant

Thank you! Any tips are greatly appreciated!

1

There are 1 best solutions below

0
On BEST ANSWER

Maybe you are mixing up 2D and 3D equations? Your getLine(P, Q) gives the equation of the plane through P, Q and (0,0,0). You could represent a line in 3D by two intersecting plane equations. Or by a vector and a direction.

Some things you could do with SymPy:

L12.subs(zip([x, y, z], P1))

results 0 if P1 belongs to the plane L12.

solve([L12, L13], (x, y, z))

finds the intersection line between planes L12 and L13: {y: 6*z, x: -z}