Go to Post I would be happy playing matches in a waffle house parking lot - mesamb1 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 25-04-2003, 11:34
Jnadke Jnadke is offline
Go Badgers!
#0093
Team Role: Alumni
 
Join Date: Jan 2002
Location: Appleton, WI
Posts: 775
Jnadke is on a distinguished road
Send a message via ICQ to Jnadke Send a message via AIM to Jnadke Send a message via Yahoo to Jnadke
Code:
' Trig routines courtesy Tracy Allen, PhD. (www.emesystems.com)

Arccosine:
  disp = disp */ 983 / 3                        ' normalize input to 127
  angle = 63 - (disp / 2)                       ' approximate angle
  DO                                            ' find angle
    IF (COS angle <= disp) THEN EXIT
    angle = angle + 1
  LOOP
  angle = angle */ 360                          ' convert brads to degrees
  RETURN


Arcsine:
  GOSUB Arccosine
  angle = 90 - angle
  RETURN
It's actually for a dual-axis accelerometer manufactured by Memsic but made by parallax. The source code is at the bottom of the page. It's the last thing in the "Dual.bs2" source file.


If we follow the link we get: this.


Code:
arctangent

'The arctangent uses the vectoring algorithm, where the value of
'y instead of z is driven to zero as a result of the decision in each 
'time through the loop. That is, by driving the tangent of the angle 
'to zero, we drive up the angle up to the value we want to find, 
'given the initial tangent of that angle.

tans  data word 32768  ' arctan 1
      data word .....  ' arctan 1/2  
      data word .....  ' arctan 1/4  
      ...
      data word .....  ' arctan 1/32678
var x  word        ' accumulated x component (cos)
var x0 word        ' a helper variable
var y  word        ' accumulated y component (sin)
var z  word        ' this will be the accumulated angle
var i  nib         ' loop counter
var A  word        ' angle read from tans table
ys var y.bit15
xs var x.bit15
zs var z.bit15
y=y0  ' we will compute the arctan
x=x0  ' based on tan theta = y0/x0
for i=0 to 15
  read 2*i,A..byte0
  read 2*i+1, A.byte1
  x=x0            ' a copy of the current value of x
  x0 = x + (-ys^(-ys^(abs y>>i) + ys)+ys)
  y = y - (-ys^(-xs ^(abs x>>i) + xs)+ys)
  z = z + (-ys^A+zs
  next
donecalc:
  x=x0
'The formula for x0 can doubtless be simplified by quite a bit, as it 
'involves double negatives.

x0 = x + (-ys^(-ys^(abs y>>i) + ys)+ys)
               ^^^^^^^^^^^^^^^^^^^------divide the abs y by 2^i
                                        and restore the sign
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---and negate if y is negative
   
so the result is positive no matter what.:

x0 = x + (abs y>>i)

Note that you need to fill in the tans table when you write your code for the algoritm to calculate properly.
__________________
The best moments of our lives fall in two categories: those that did happen and those that did not.

Last edited by Jnadke : 25-04-2003 at 13:39.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Obscure PBASIC for RoboEmu rbayer Programming 1 28-03-2003 23:57
PBasic 2.5 vs. 2.0 Anthony Kesich Programming 6 09-02-2003 22:06
PBASIC Loop Speed? archiver 2001 3 23-06-2002 23:46
Subtotaling in PBASIC? Ian W. Programming 17 02-02-2002 20:22
Simplifying PBasic IDiggles General Forum 16 06-11-2001 01:36


All times are GMT -5. The time now is 09:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi