How to do ARCTAN (inverse tan) in PICBasic Pro


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005
    Posts
    19

    Default How to do ARCTAN (inverse tan) in PICBasic Pro

    Arctan() is a trigonometric function. It is the inverse function of the tangent function, tan(). That is,

    tan(x) = y implies arctan(y) = x ; for all x

    How to do the arctan operation in picbasic pro?

    TQ

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Although a tad code heavy, lookup table or similar is easy and fast

    in degrees
    tan(0.5) = .008727 = 2/256
    tan(1.5) = .026186 = 6/256
    ...
    tan(5.5) = .09626289 = 24/256
    tan(20.5) = .373885 = 95/256
    tan(60.5) = 1.767494 = 452/256
    tan (89.5) = 114.5887 = 29334/256

    Use Excel or similar to determine all values you need for the accuracy you need (my table has all values from 0.5 to 89.5 by steps of 1, i.e., 0.5,1.5,2.5,3.5,......88.5,89.5 and therefore has 90 if-then statements) Watch for word overflow for angles above 89.77 degrees because tan(89.78) = 66671/256 and 66671 > word)

    In code

    atan var word
    deg var byte

    if atan < 29334 then deg = 89
    if atan < 452 then deg = 60
    if atan < 95 then deg = 20
    if atan < 24 then deg = 5
    if atan < 6 then deg = 1
    if atan < 2 then deg = 0

    Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

Similar Threads

  1. picbasic pro and mplab IDE
    By soelinnhtet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st March 2010, 08:57
  2. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  3. Chipselect Var PORTD,Vecto4X Compass
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th April 2006, 01:50
  4. Question for all that use MELABS PICBASIC PRO
    By oskuro in forum Off Topic
    Replies: 2
    Last Post: - 24th March 2005, 17:15
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts