fork download
  1. import math
  2.  
  3.  
  4. def half_angle_tangent(full_tangent):
  5. # http://m...content-available-to-author-only...m.com/Half-AngleFormulas.html
  6. return (math.sqrt(1 + full_tangent * full_tangent) - 1) / full_tangent
  7.  
  8.  
  9. def n_subdivisions_perimeter(n):
  10. # seg_l/2 = r * tg(angle)
  11. # starting from 45° (tg = 1, 4 segments, cube)
  12. tang, subs = 1.0, 4
  13. for i in range(n):
  14. tang = half_angle_tangent(tang)
  15. subs *= 2
  16. return tang * 2 * subs
  17.  
  18.  
  19. if __name__ == '__main__':
  20. for n in range(10):
  21. print('n={}: {}'.format(
  22. n,
  23. n_subdivisions_perimeter(n) / 2
  24. ))
  25.  
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
n=0: 4.0
n=1: 3.313708498984761
n=2: 3.1825978780745294
n=3: 3.151724907429258
n=4: 3.1441183852458665
n=5: 3.142223629942345
n=6: 3.141750369169704
n=7: 3.141632080702249
n=8: 3.141602510241972
n=9: 3.1415951177183654