From: jsavard@tenMAPSONeerf.edmonton.ab.ca (John Savard) Subject: Re: Cordic Algorithm Date: Tue, 25 May 1999 21:14:32 GMT Newsgroups: sci.math Tom Hubin wrote, in part: >I read a reference to the Cordic Algorithm for rectangular/polar >conversions. It was used in a microcontroller for compass direction from >a dual axis analog Hall Effect sensor. I have a similar application so I >would like to get detailed info on the algorithm. Any suggestions on >this or any other RtoP or PtoR conversions to the nearest 0.1 degree. The basic idea of the CORDIC algorithm is as follows: If you have a vector (x,y), you can rotate that vector by multiplying it by a suitable matrix. Thre is a family of very simple matrices that make multiplication really fast which both rotate and enlarge the vector. So, one starts with a vector whose length is the inverse of all these enlargements, and one ends up with the desired co-ordinates, given an angle. In the reverse direction, take the co-ordinates as input, and transform them so that a vector of the form (x,0) will be obtained when it is rotated by the correct angle. The simple matrices are: rotate 45 degrees and multiply length by sqrt(2) 1 -1 1 1 1 1 or -1 1 rotate by atan(1/2) and multiply length by sqrt(5)/2 1 -.5 1 .5 .5 1 or -.5 1 rotate by atan(1/4) and multiply length by sqrt(17)/4 1 -.25 1 .25 .25 1 or -.25 1 rotate by atan(1/8) and multiply length by sqrt(65)/8 1 -.125 1 .125 .125 1 or -.125 1 and so on and you choose to multiply by the first matrix (counterclockwise) or the second matrix (clockwise) at each step (you can't choose to skip a multiply or stop early) - each multiplication is just a shift and add - whichever one makes the angle or the co-ordinates closer to your target (the other one being your answer). Hopefully, this explains the CORDIC algorithm well enough to allow you to use and implement it. John Savard ( teneerf<- ) http://members.xoom.com/quadibloc/index.html