Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 13
Registered: ‎05-21-2009
My Device: Not Specified

Re: MathUtilities alternatives to pow, acos, asin, atan?

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.

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: MathUtilities alternatives to pow, acos, asin, atan?

[ Edited ]

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.

 

Good luck,

~Dom

 

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?

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
New Developer
Posts: 13
Registered: ‎05-21-2009
My Device: Not Specified

Re: MathUtilities alternatives to pow, acos, asin, atan?

I ended up going with the following open source library for acos, asin, and atan. It's licensed via the Apache License 2.0.

 

http://code.google.com/p/j4me/

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: MathUtilities alternatives to pow, acos, asin, atan?

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.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: MathUtilities alternatives to pow, acos, asin, atan?

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/crdcsrvy.pdf). They are the basis for many hardware implementations, are quite fast, and only require shift and add operations.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: MathUtilities alternatives to pow, acos, asin, atan?

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.

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: MathUtilities alternatives to pow, acos, asin, atan?

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.

 

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX