This include file allows you to perform the arctangent (atan2) & hypotenuse or sine & cosine. It uses an cordic equation, written in assembly to get to a quick 16 bit solution. This solution is accurate within 0.01%, according to the original author. The results of sin and cos are returned as a pair, in the same step. Also, the results of atan2, and the hypotenuse is also given as a pair in one step. See

www.chiefdelphi.com/media/papers/2016 for more information. Using the code from Pat Fairbank, I modified it to work with PicBasic Pro, on a PIC18F device. (This was done with a lot of help from Darrel Taylor). The original code was touted to be 90 times faster than math.h, if you are into C.

Atan2 can be used to calculate distance and heading to lat and long co-ordinates, and also to calculate tilt, among many other equations.

Examples for use:

sincos example:

ang : input angle in degrees.dd example: ang = 3000 (= 30.00 degrees)

call sincos

result : x = 15004 , y = 25981

so, 15004/30000 = sin(ang) = 0.5001 and 25981/30000 = cos(ang) = 0.8660

atan2 example:

input x,y co-ordinates

x = 25981, y = 15000

call atan2

result: x = 29998 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 5998 (=59.98 degrees), ang = 5463 = radians 0 to 65535

For more info, see the thread here

www.picbasic.co.uk/forum/showthread.php
Quoted from

www.dspguru.com/info/faqs/cordic.htm :

"CORDIC is an acronym that stands for COordinate Rotation DIgital Computer, and was coined

by Volder [Volder 59]. Its concepts have been further developed to include calculation of the Discrete

Fourier Transform [Despain 74], exponential, logarithm, forward and inverse circular and hyperbolic

functions, ratios and square roots [Chen 72] [Walther 71], and has been applied to the antialiasing

of lines and polygons [Turkowski 82].

It is an iterative fixed-point technique that achieves approximately one more bit of accuracy with

each iteration. In spite of merely linear convergence, the inner loop is very simple, with arithmetic

that consists of only shifts and adds, so it is competitive with (and even outperforms) floating-

point techniques with quadratic convergence, for the accuracy typically required for 2-dimensional

raster graphics."

by

scalerobotics
## Re: Goodbye

not to mention a vast array of cheap "Arduino compatible" sensors/modules in a breadboard friendly form, making it easy to hook up something up

richard Yesterday, 02:00to test our wildest ideas with no immediate need for...