Posted By

ianbaldy on 11/13/10


Tagged

math python Geometry


Versions (?)

Curvature of point set


 / Published in: Python
 

  1. import math
  2. import sys
  3.  
  4. class geometry:
  5.  
  6. def __init__(self):
  7. self.name = ''
  8.  
  9. def curvature( self, list ):
  10. if ( len( list ) < 3 ):
  11. #Too few points
  12. sys.exit( 0 )
  13. return -1
  14. else:
  15. x1 = list[0][0]
  16. y1 = list[0][1]
  17. x2 = list[1][0]
  18. y2 = list[1][1]
  19. x3 = list[2][0]
  20. y3 = list[2][1]
  21.  
  22. num = 2*((x2-x1)*(y3-y2)-(y2-y1)*(x3-x2));
  23. 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) ) );
  24.  
  25. if ( den == 0 ):
  26. return 0
  27.  
  28. return num/den

Report this snippet  

You need to login to post a comment.