Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three Point Circle solution in Clear category for Three Points Circle by Damian_Horna
import math
def checkio(data):
(x1,y1), (x2,y2), (x3,y3) = eval(data)
#budujemy układ trzech równań, z którego otrzymujemy:
d=2.0 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
x=((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2)
* (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
y=((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2)
* (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
r=math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
#---------------------------------------------------
x=round(x,2)
y=round(y,2)
r=round(r,2)
return "(x-{:g})^2+(y-{:g})^2={:g}^2".format(x,y,r)
Oct. 23, 2016
Comments: