Shop OBEX P1 Docs P2 Docs Learn Events
Arcsine/Arccosine Lookup Table? — Parallax Forums

Arcsine/Arccosine Lookup Table?

Carl LawhonCarl Lawhon Posts: 36
edited 2009-02-15 00:01 in Propeller 1
Does anyone have a lookup table for the inverse trig functions? I basically need to be able to calculate an angle given x and y cartesian coordinates. Thanks in advance for your help.

Carl Lawhon

EDIT: I neglected to mention that I would like to be able to determine angles in all four quadrants, not just 0 to 90 degrees.

Post Edited (Carl Lawhon) : 2/14/2009 2:06:17 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-14 03:03
    Try CORDIC. Beau wrote a CORDIC routine in assembly (for speed) that does arctangent (for use with the HM55B compass). You can find it as part of BoeBotBasic. The assembly routine is at the end of the program and the routine that interfaces with it is around line 500 (for the COMPASS statement).
  • Carl LawhonCarl Lawhon Posts: 36
    edited 2009-02-14 03:22
    Thanks!
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-02-14 03:27
    You can make your own tables for any function rather easily. Create an Excel spreadsheet containing in one column the input variable in the range and increment you desire (Excel will generate this for you), and in another column the computed function, and in another column the letters WORD or LONG or BYTE, as desired. Copy these columns into blank lines in a Spin file, and -- voil
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-02-14 05:11
    Carl Lawhon,
    ·
    Try this and see if it will work for you.· It uses a free COG to temporarily launch an Assembly routine to calculate the·Angle.· When it's done it frees the COG.· The CORDIC routine was originally written by Chip Gracey·so my understanding of it is somewhat limited.· I also did a successive approximation reverse Sine table lookup that basically plays the classic game... "pick a number between 1 and 100" ...but it finds the answer in the least number of possible guesses.· I'll try to dig that up and wrap a·callable routine around that as well.
    ·
    ··

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 2/14/2009 5:16:41 AM GMT
  • Jack CrenshawJack Crenshaw Posts: 46
    edited 2009-02-14 14:34
    First, I would not use arcsine or arccos -- the power series converge too slowly. Instead, use the arctangent.

    Second, there are two ways to compute any function. One is by power series or other math formula. The second is table lookup. I almost always tend to use math formulas, but in these days of big memory space, sometimes a table is better. It's almost always FASTER, if done properly.

    Third, the power series for arctan converges even slower than the one for arcsine. Instead, use the continued-fraction form. It converges VERY fast, to the extent that you only need about third order for many uses (like yours).

    Fourth, no matter how you do it, you'll need to use the function in segments. The tangent function goes to infinity, after all, at 90 degrees. In your case, by comparing the x- and y-axis values, you can always find an argument with abs value less than or equal to 1.

    To see the problem done ad infinitum, with multiple segments, ultra-simple formulas, and coefficients optimized using minimax techniques, see my book, "Math Toolkit":

    http://www.amazon.com/Math-Toolkit-Real-Time-Programming-Crenshaw/dp/1929629095

    Jack
  • Jay KickliterJay Kickliter Posts: 446
    edited 2009-02-14 14:56
    Jack, I was looking at your book the other day on Amazon. What level of math and or programming experience do you need to understand it? Particularly, for someone like me with a decent skills in using calculus, if not understanding it all the way, not terribly great at algebra, and some programming experience, will I be lost?

    I'm asking because I've been working on making a more efficient use of cogs to handle accelorometers/gyros, but I really don't know what I'm doing. Are kalman filters necessary, and are there any other alternatives?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-02-14 16:15
    Carl Lawhon,

    Here is the Cordic routine that I posted earlier with a reverse lookup ArcSine routine that I mentioned as well added.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Jack CrenshawJack Crenshaw Posts: 46
    edited 2009-02-15 00:01
    Jay Kickliter said...

    Jack, I was looking at your book the other day on Amazon. What level of math and or programming experience do you need to understand it? Particularly, for someone like me with a decent skills in using calculus, if not understanding it all the way, not terribly great at algebra, and some programming experience, will I be lost?

    I'm asking because I've been working on making a more efficient use of cogs to handle accelorometers/gyros, but I really don't know what I'm doing. Are kalman filters necessary, and are there any other alternatives?

    Jay, the stuff on trig functions is all algebra (and trig, of course). No calculus. The second half of the book is _ALL_ calculus, but it starts at a very fundamental level, and works its way up. My whole teaching style is to make sure that "No child is left behind," and that's the way the book is written.

    I feel that I should explain why I don't just post the arctan on my web site: I don't have a web site wink.gif. I'm working on it, and intend to post all kinds of goodies there.

    Re the gyros, etc.: I wrote a series in Embedded Systems called "Secrets of the Spin Doctors":

    "Secrets of the Spin Doctors," Embedded Systems Programming, Vol. 7, #4, April 1994, pp. 40-63.
    "More Secrets of the Spin Doctors," Embedded Systems Programming, Vol. 7, #5, May 1994, pp. 58-67.
    "Spin Doctors at Work," Embedded Systems Programming, Vol. 7, #7, July 1994, pp. 54-73.

    I think this series might be just what you need. I _THINK_ it's on the ESD CDROM, but you'd better check first.

    I have tons of algorithms and models to do attitude calculations. I plan to post them, too, Real Soon Now. Eventually, I hope to be able to offer Spin versions to the library here. Real Soon Now.

    Jack
Sign In or Register to comment.