pythontriangulation

How to find the value of x and y using the given mathematical expression


How can I transform the given mathematical expression in python to find x & y value?

(x-x2)**2 + (y-y2)**2 = d1**2   ====> 1 
(x-x3)**2 + (y-y3)**2 = d3**2   ====> 2

By subtracting one from another,
2(x3-x2)x+2(y3-y2)y+(x2**2-x3**2+y2**2-y3**2)=d1**2-d3**2  ====> 3

The another value can be find out by substituting the obtained value from 3 in either 1 or 2.

How can I achieve the process in python?


Solution

  • I don't exactly know your expected outcome, because I don't know what your variables are. Generally, use sympy to define your algebra:

    import sympy as smp
    from sympy.solvers.polysys import solve_poly_system
    
    # Define variables
    x, x2, x3, y, y2, y3, d, d3 = smp.symbols("x x_2 x_3 y y_2 y_3 d_1  d_3")
    # Define equations
    eq1 = smp.Eq((x - x2)**2 + (y - y2)**2, d**2)
    eq2 = smp.Eq((x - x3)**2 + (y - y3)**2, d3**2)
    

    You could then solve the equation system with one of sympys solvers. I guess you want solve_poly_system