Last active
August 29, 2015 14:17
-
-
Save dohyunkim/3a8aacc6cfaeaab3e50c to your computer and use it in GitHub Desktop.
Two versions of Pi spiral. In the latter, Pi is calculated by MetaPost thanks to its `decimal` number system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \documentclass[margin=4pt]{standalone} | |
| \usepackage{fontspec} | |
| \setmainfont{Helvetica} | |
| \usepackage{luamplib} | |
| \mplibnumbersystem{double} | |
| \mplibtextextlabel{enable} | |
| \edef\pidecimal{\directlua{ | |
| local pidec = [[ | |
| 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 | |
| 58209 74944 59230 78164 06286 20899 86280 34825 34211 70679 | |
| 82148 08651 32823 06647 09384 46095 50582 23172 53594 08128 | |
| 48111 74502 84102 70193 85211 05559 64462 29489 54930 38196 | |
| 44288 10975 66593 34461 28475 64823 37867 83165 27120 19091 | |
| 45648 56692 34603 48610 45432 66482 13393 60726 02491 41273 | |
| 72458 70066 06315 58817 48815 20920 96282 92540 91715 36436 | |
| 78925 90360 01133 05305 48820 46652 13841 46951 94151 16094 | |
| 33057 27036 57595 91953 09218 61173 81932 61179 31051 18548 | |
| 07446 23799 62749 56735 18857 52724 89122 79381 83011 94912 | |
| ]] | |
| tex.sprint('"'..pidec:gsub(" ","")..'..."') | |
| }} | |
| \begin{document} | |
| \begin{mplibcode} | |
| beginfig(0); | |
| degree := 180; radius := 35; | |
| drawoptions(withcolor .8red); | |
| label.top("3.", origin) rotated (degree - 90) | |
| shifted (radius * dir(degree-1)); | |
| string pidec; pidec := \pidecimal ; | |
| for i=1 upto length(pidec): | |
| degree := degree - 10; radius := radius * 0.995; | |
| label.top(substring(i-1,i) of pidec, origin) scaled (radius / 35) | |
| rotated (degree - 90) | |
| shifted (radius * dir degree); | |
| endfor | |
| label("$\pi$", origin) scaled .9; | |
| endfig; | |
| \end{mplibcode} | |
| \end{document} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \documentclass[margin=4pt]{standalone} | |
| \usepackage{fontspec} | |
| \setmainfont{Helvetica} | |
| \usepackage{luamplib} | |
| \mplibnumbersystem{decimal} | |
| \mplibtextextlabel{enable} | |
| \begin{document} | |
| \begin{mplibcode} | |
| numberprecision := 503; | |
| numeric a[], b[], t[], p[], PI, degree, radius; string pidec; | |
| degree = 180; radius = 35; | |
| % Gauss–Legendre algorithm | |
| a0 = p0 = 1; | |
| b0 = 1/sqrt(2); | |
| t0 = 1/4; | |
| for i=1 upto 8: | |
| h := i -1; | |
| a[i] = (a[h] + b[h])/2; | |
| b[i] = sqrt(a[h] * b[h]); | |
| t[i] = t[h] - p[h] * ((a[h] - a[i])**2); | |
| p[i] = 2 * p[h]; | |
| PI := (a[i] + b[i])**2/(4 * t[i]); | |
| endfor | |
| pidec := substring (2, 502) of decimal PI & "..."; | |
| numberprecision := 34; | |
| beginfig(0); | |
| drawoptions(withcolor .8red); | |
| label.top("3.", origin) rotated (degree - 90) | |
| shifted (radius * dir(degree-1)); | |
| for i=1 upto length(pidec): | |
| degree := degree - 10; radius := radius * 0.995; | |
| label.top(substring(i-1,i) of pidec, origin) scaled (radius / 35) | |
| rotated (degree - 90) | |
| shifted (radius * dir degree); | |
| endfor | |
| label("$\pi$", origin) scaled .9; | |
| endfig; | |
| \end{mplibcode} | |
| \end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment