java - How to calculate exact value of a trig function? -


i writing "triangle solver" app android, , wondering if possible implement exact values trig ratios , radian measures. example, 90 degrees output "pi / 2" instead of 1.57079632679...

i know in order exact value radian measure, divide pi , convert fraction. don't know how convert decimal fraction.

like this:

int decimal = anglemeasure / math.pi; somemethodtoturnitintoafraction(decimal); 

i don't know begin trig ratios.

you need take number , divide each of "special" numbers: pi,e, sqrt(2), sqrt(3), sqrt(5). after each division, determine if resulting number close exact fraction. last part, use continued fraction algorithm find approximations number. there criteria can use in continued fraction expansion determine if approximation exact. if nice fraction small numbers exact that's answer - fraction times special number divided @ beginning. oh , consider "1" divisor simple fractions come out too.

been there, done that, works well. don't recall algorithm getting approximate fractions without storing , collapsing entire continued fraction, it's been linked here on recently.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -