import math
def half_angle_tangent(full_tangent):
# http://m...content-available-to-author-only...m.com/Half-AngleFormulas.html
return (math.sqrt(1 + full_tangent * full_tangent) - 1) / full_tangent
def n_subdivisions_perimeter(n):
# seg_l/2 = r * tg(angle)
# starting from 45° (tg = 1, 4 segments, cube)
tang, subs = 1.0, 4
for i in range(n):
tang = half_angle_tangent(tang)
subs *= 2
return tang * 2 * subs
if __name__ == '__main__':
for n in range(10):
print('n={}: {}'.format(
n,
n_subdivisions_perimeter(n) / 2
))
aW1wb3J0IG1hdGgKCgpkZWYgaGFsZl9hbmdsZV90YW5nZW50KGZ1bGxfdGFuZ2VudCk6CiAgICAjIGh0dHA6Ly9tLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5tLmNvbS9IYWxmLUFuZ2xlRm9ybXVsYXMuaHRtbAogICAgcmV0dXJuIChtYXRoLnNxcnQoMSArIGZ1bGxfdGFuZ2VudCAqIGZ1bGxfdGFuZ2VudCkgLSAxKSAvIGZ1bGxfdGFuZ2VudAoKCmRlZiBuX3N1YmRpdmlzaW9uc19wZXJpbWV0ZXIobik6CiAgICAjIHNlZ19sLzIgPSByICogdGcoYW5nbGUpCiAgICAjIHN0YXJ0aW5nIGZyb20gNDXCsCAodGcgPSAxLCA0IHNlZ21lbnRzLCBjdWJlKQogICAgdGFuZywgc3VicyA9IDEuMCwgNAogICAgZm9yIGkgaW4gcmFuZ2Uobik6CiAgICAgICAgdGFuZyA9IGhhbGZfYW5nbGVfdGFuZ2VudCh0YW5nKQogICAgICAgIHN1YnMgKj0gMgogICAgcmV0dXJuIHRhbmcgKiAyICogc3VicwoKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBmb3IgbiBpbiByYW5nZSgxMCk6CiAgICAgICAgcHJpbnQoJ249e306IHt9Jy5mb3JtYXQoCiAgICAgICAgICAgIG4sCiAgICAgICAgICAgIG5fc3ViZGl2aXNpb25zX3BlcmltZXRlcihuKSAvIDIKICAgICAgICApKQo=