Created
January 3, 2018 15:07
-
-
Save arvsrao/1d3895013fa2a87b45396676c8f508d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy import * | |
from sympy.solvers import solve | |
x = Symbol('x', real=true) | |
y = Symbol('y', real=true) | |
x0 = Symbol('x0', real=true) | |
x1 = Symbol('x1', real=true) | |
x2 = Symbol('x2', real=true) | |
y0 = Symbol('y0', real=true) | |
y1 = Symbol('y1', real=true) | |
y2 = Symbol('y2', real=true) | |
mb = (y1- y0)/(x1-x0) | |
mc = (y2- y1)/(x2-x1) | |
# midpoints | |
bx = (x1 + x0)/2 | |
by = (y1 + y0)/2 | |
cx = (x2 + x1)/2 | |
cy = (y2 + y1)/2 | |
# Solve system of equations to find the intersection | |
# equations of lines that bisect | |
# -1/mb (x - bx) = y - by | |
# -1/mc (x - cx) = y - cy | |
bisector1 = -1/mb *(x - bx) - y + by | |
bisector2 = -1/mc *(x - cx) - y + cy | |
# point where besectors intersect | |
xi = solve(bisector1 -bisector2, x)[0] | |
yi = solve(bisector1.subs(x, xi),y)[0] | |
# lengths of line segments from points to (xi,yi) | |
d0 = (xi-x0)**2 + (yi-y0)**2 | |
d1 = (xi-x1)**2 + (yi-y1)**2 | |
d2 = (xi-x2)**2 + (yi-y2)**2 | |
# show lengths of line segments are all the same | |
# d0 == d1 == d2 | |
(simplify(d1 - d0) == 0) and (simplify(d2 - d1) == 0) and (simplify(d2 - d0) == 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment