## 2013-04-10

### $\frac{πp}{r}$: a slice of π

In a previous post I made a doohickey to convert decimals into fractions. It occurred to me that with a tiny bit of tweaking, we could make it work for fractions of pi, too.

### Easy as... you know

One of my hopes with all this math and Raphaël stuff recently is that I'll eventually be able to create an interactive graph of the unit circle. The unit circle, in case you don't know, looks like this:

 Thanks, Wikimedia!

It makes it easy to visualize the values of sine and cosine. Anyway, that's not relevant right now; the important thing for our purposes is that the values are always fractions of pi. If and when I make this thing, I don't want to have to create a massive lookup table with every conceivable value of every realistically necessary fraction of pi.

So I want to make the Fractionizer do it for me.

To search for fractions of pi, all we need do is divide by pi and then search for the fraction as before. If there is a match, we just return the numerator with 'π' appended to it.

Again, there is an obvious limitation in that we cannot enter the precise value of pi. It is after all by its very nature impossible to write down precisely, what with being an irrational number and all. We have to make do with using Javascript's Math.PI. Not exact by any means, but it works to a degree of precision that will do for most mundane purposes, and mine are seldom anything but.

Speaking of which...

One problem with this script is having to pick an arbitrary precision at which to assume infinite recursion. This is why it can never be perfect, because it's entirely possible that you might want to fractionize an extreme value such as $0.3333333333$ (which is of course $\frac{3333333333}{10000000000}$, but is determined to be $\frac{1}{3}$ by the script). I don't think this is something that has a solution, other than altering the precision manually when called for.