# Zu Chongzhi's calculation of pi (China, about 480 A.D.),
# approximating the circle from inside by a regular 12288-polygon(!):
phi <- seq(0, 2*pi, len=3*2^12+1)
x <- cos(phi)
y <- sin(phi)
pi_approx <- polyarea(x, y)
print(pi_approx, digits=8) #=> 3.1415925 or 355/113
poly_length(x, y) #=> 6.2831852 where 2*pi is 6.2831853
x1 <- x + 0.5; y1 <- y + 0.5
x2 <- rev(x1); y2 <- rev(y1)
poly_center(x1, y1) #=> 0.5 0.5
poly_center(x2, y2) #=> 0.5 0.5
Run the code above in your browser using DataLab