back to table · edit · history · where entries came from · files · download
487 bytes, as of the version from 2026-10-24 21:50 (current). Recorded here, not run.
# Mean distance to the centroid of a regular n-gon of circumradius R.
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField
def mean_regular_polygon(n, R=1, digits=100):
if n < 3:
raise ValueError("n must be at least 3")
F = RealBallField(numberdb.bits(digits, losing=80))
theta = F.pi()/n
h = F(R)*theta.cos()
return h/3*(1/theta.cos()
+(1/theta.cos()+theta.tan()).log()/theta.tan())
print(mean_regular_polygon(6))