from Numeric import * from numarray.linear_algebra import * class circle_solve: def __init__(self,x1,y1,x2,y2,x3,y3): self.x1=x1 self.y1=y1 self.x2=x2 self.y2=y2 self.x3=x3 self.y3=y3 def print_points(self): print "For points X1= %0.4f Y1= %0.4f, X2= %0.4f Y2=%0.4f, X3= %0.4f Y3 %0.4f " % (self.x1, self.y1, self.x2, self.y2, self.x3, self.y3) #print self.x1, self.y1, self.x2, self.y2 ,self.x3, self.y3 def solve_it(self): M11_array = array(((self.x1,self.y1,1),(self.x2,self.y2,1),(self.x3,self.y3,1))) M11 = determinant(M11_array) M12_array=array((((self.x1*self.x1)+(self.y1*self.y1),self.y1,1),((self.x2*self.x2)+(self.y2*self.y2),self.y2,1),((self.x3*self.x3)+(self.y3*self.y3),self.y3,1))) M12 = determinant(M12_array) M13_array=array((((self.x1*self.x1)+(self.y1*self.y1),self.x1,1),((self.x2*self.x2)+(self.y2*self.y2),self.x2,1),((self.x3*self.x3)+(self.y3*self.y3),self.x3,1))) M13 = determinant(M13_array) M14_array=array((((self.x1*self.x1)+(self.y1*self.y1),self.x1,self.y1),((self.x2*self.x2)+(self.y2*self.y2),self.x2,self.y2),((self.x3*self.x3)+(self.y3*self.y3),self.x3,self.y3))) M14 = determinant(M14_array) x_center = .5 * (M12/M11 ) y_center = -.5 * (M13/M11 ) radius = (( x_center **2) + (y_center **2) + (M14/M11))**.5 print "Arc center = %0.8f, %0.8f, with radius R %0.8f" % (x_center, y_center, radius) # how to use this class: one = circle_solve(0,.18,.25,0,.37,.012) two = circle_solve(0,.18,-.0493,.3235,-0.0521,0.6357) one.print_points() one.solve_it() two.print_points() two.solve_it()