/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import math import sys class geometry: def __init__(self): self.name = '' def curvature( self, list ): if ( len( list ) < 3 ): #Too few points sys.exit( 0 ) return -1 else: x1 = list[0][0] y1 = list[0][1] x2 = list[1][0] y2 = list[1][1] x3 = list[2][0] y3 = list[2][1] num = 2*((x2-x1)*(y3-y2)-(y2-y1)*(x3-x2)); den = math.sqrt( (math.pow((x2-x1),2) + math.pow((y2-y1),2)) * (math.pow((x3-x2),2)+math.pow((y3-y2),2 ))* (math.pow((x1-x3),2)+math.pow((y1-y3),2) ) ); if ( den == 0 ): return 0 return num/den