In [7]:
import sympy
from sympy import *
In [8]:
a,b,xa,ya,xb,yb,xt,yt = symbols('A B a_x a_y b_x b_y t_x t_y')
In [9]:
x_expr = Eq(a*xa+b*xb,xt)
y_expr = Eq(a*ya+b*yb,yt)
x_expr
Out[9]:
In [10]:
a_expr = solve(x_expr,a)
a_eq = Eq(a,a_expr[0])
a_eq
Out[10]:
In [13]:
b_expr = y_expr.subs(a, a_expr[0])
b_eq = Eq(b, b_expr)
b_eq
Out[13]:
In [15]:
b_expr = solve(b_expr,b)
b_eq = Eq(b,b_expr[0])
b_eq
Out[15]:
In [18]:
a_expr = a_eq.subs(b, b_expr[0])
a_expr
Out[18]:
In [35]:
a_expr = simplify(a_expr)
a_expr
Out[35]:
In [37]:
b_eq = simplify(b_eq)
b_eq
Out[37]:
In [33]:
print(a_expr)
print(b_eq)
Eq(A, (-b_x*t_y + b_y*t_x)/(a_x*b_y - a_y*b_x)) Eq(B, (a_x*t_y - a_y*t_x)/(a_x*b_y - a_y*b_x))
In [ ]: