-2

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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Mahamutha M
  • 1,235
  • 1
  • 8
  • 24

2 Answers2

1

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

flurble
  • 1,086
  • 7
  • 21
1

Using sympy factor

import sympy as sp

x, x2, x3, y, y2, y3, d, d3 = sp.symbols("x x2 x3 y y2 y3 d1  d3")
eq1 = (x - x2)**2 + (y - y2)**2- d**2
eq2 = (x - x3)**2 + (y - y3)**2- d3**2
print(sp.factor(eq1-eq2,x,y))
# -d1**2 + d3**2 - x*(2*x2 - 2*x3) + x2**2 - x3**2 - y*(2*y2 - 2*y3) + y2**2 - y3**2
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59