04-21-2010 07:41 AM
My unit tests are failing with the implementations of the inverse trig methods added to this post so it doesn't look like it's that easy. I'm going to to check Google code as was suggested for additional implementations.
04-21-2010 08:53 AM - edited 04-21-2010 09:06 AM
Hey all, sorry for the mixup with the code. Haven't had to do trig for awhile, and honestly I'm a little burnt out these days. I'll be more careful in the future. I fixed the examples to be more accurate. Now then, after doing a little review, y = arcSin x when x = sin y (I was thinking of csc, not asin...). Off the top of my head, I can't think of a simple way to accomplish this, as despite fervent requests in high school nobody ever showed me how to do trig manually. I may come back to this later.
EDIT: Working through some of the concept math...
sin x = o / h = y
arcsin (o / h) = x
h = sqrt (o**2 + a**2)
sin x = o / sqrt (o**2 + a**2)
Yeah, I've still got nothing. Anyone?
04-22-2010 04:20 PM
I ended up going with the following open source library for acos, asin, and atan. It's licensed via the Apache License 2.0.
04-22-2010 05:56 PM
The non-clever way to do this is to use a traditional Taylor series expansion of these functions and "burn in" the coefficients in a lookup table or something.
Taylor series usually do not have very fast convergence speed, so there are undoubtedly more sophisticated ways to do this.
04-22-2010 06:16 PM
If you're going to build a lookup table, do it off-line and generate Java source with the lookup table. That way you can use a decent math library to do the actual calculation and no need for Taylor series expansion.
For doing the calculations on a low-end computer (not to disparage RIM, but let's be real), I think that a common approach for the inverse trig functions is to use inverse CORDIC algorithms. (See, e.g., http://www.ee.ic.ac.uk/pcheung/teaching/ee3_DSD/cr
04-22-2010 06:26 PM
Doing that is fine too, obviously, except you're trading memory for accuracy again. Anyway, Taylor series are more often than not so inefficient they're not really worth considering in a production environment.
04-23-2010 09:48 AM
I think I'm officially out fo my league, here (I tried reading the CORDIC Publication, but my eyes began to glaze over halfway through Page 3...). I defer to the expertise of my colleagues, and humbly take my leave.