Center and radius of a circle...
given three points in a plane
What follows is a Python.3.7 program. It must be installed to get results.
#Given three points (a,b),(c,d),(e,f) in a plane
print ('type, one at a time, a, b, c, d, e, f')
a=float(input())
b=float(input())
c=float(input())
d=float(input())
e=float(input())
f=float(input())
if a*d+b*e+c*f-e*d-b*c-a*f==0:
print('collinear points')
quit()
else:
a1=(2*(a-e))
a2=(2*(e-c))
b1=(2*(b-f))
b2=(2*(f-d))
c1=(-a**2-b**2+e**2+f**2)
c2=(c**2+d**2-e**2-f**2)
k=(a2*b1-a1*b2)
m=(c1*b2-c2*b1)*(k**-1)
g=(a1*c2-a2*c1)*(k**-1)
t=m-a
u=g-b
h1=t**2+u**2
h2=h1**.5
print('Center coordinates are: (',m,',',g,')')
print('Radius ',h2)
Example (1) For (3,-4), (1, 5), (2,0)
3
-4
1
5
2
0
Center coordinates are: ( 96.5 , 21.5 )
Radius, 96.91491113342673
Example(2) For (2, 3), (1, 5), (4, -1)
2
3
1
5
4
-1
collinear points
The program must be closed.
b=float(input())
c=float(input())
d=float(input())
e=float(input())
f=float(input())
if a*d+b*e+c*f-e*d-b*c-a*f==0:
print('collinear points')
quit()
else:
a1=(2*(a-e))
a2=(2*(e-c))
b1=(2*(b-f))
b2=(2*(f-d))
c1=(-a**2-b**2+e**2+f**2)
c2=(c**2+d**2-e**2-f**2)
k=(a2*b1-a1*b2)
m=(c1*b2-c2*b1)*(k**-1)
g=(a1*c2-a2*c1)*(k**-1)
t=m-a
u=g-b
h1=t**2+u**2
h2=h1**.5
print('Center coordinates are: (',m,',',g,')')
print('Radius ',h2)
Example (1) For (3,-4), (1, 5), (2,0)
3
-4
1
5
2
0
Center coordinates are: ( 96.5 , 21.5 )
Radius, 96.91491113342673
Example(2) For (2, 3), (1, 5), (4, -1)
2
3
1
5
4
-1
collinear points
The program must be closed.
No hay comentarios:
Publicar un comentario