mobile02 发表于 2014-11-22 20:50:52

求ATAN2_16bit函数代码(最好是查表法)

找到一个 8bit 的方式,怎么计算 16bit 的表?

/***************************************************************************************
** 名    稱: atan2_8bit
** 參    數: a: 正弦值,b: 餘弦值
** 返    回: 角度(-127 ~ 127)
** 描    述: 反正切
**
***************************************************************************************/
signed char atan2(signed char x,signed char y)
{
    unsigned char code myangle[] =
    {
   /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64 */
      0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10,11,11,12,13,14,15,16,17,17,18,19,20,21,21,22,23,24,24,25,26,27,27,28,29,29,30,31,31,32,33,33,34,35,35,36,36,37,37,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45
    };
    bit nx = (x < 0),ny = (y < 0),cb;
   
    if(x < 0)
      x = -x;
    if(y < 0)
      y = -y;
    if(x < y)
      x = 90 - myangle;//余切值*64
    else
      x = myangle;//正切值*64
    if(nx)
    {
      if(180 - x > 127)
            x = 127;
      else
            x = 180 - x;
    }
    if(ny)
      x = -x;
    return x;
}

again 发表于 2014-11-23 13:18:00

cordic atan2

again 发表于 2014-11-23 13:19:18

http://www.amobbs.com/forum.php?mod=viewthread&tid=3795383&highlight=cordic

mobile02 发表于 2014-11-23 14:25:39

again 发表于 2014-11-23 13:19
http://www.amobbs.com/forum.php?mod=viewthread&tid=3795383&highlight=cordic

那个好像使用 DSP计算,我的 CPU没有 DSP...{:sad:}

chenchaoting 发表于 2014-11-23 14:40:21

不需要DSP,知道原理就相当简单。整数加减与移位就可以了

mobile02 发表于 2014-11-23 20:46:05

chenchaoting 发表于 2014-11-23 14:40
不需要DSP,知道原理就相当简单。整数加减与移位就可以了

那楼上的范例表是怎么产生的?{:smile:}

chenchaoting 发表于 2014-11-23 21:11:57

你说的是again 网友说的表么?那个表分别是arctan(1),arctan(0.5),arctan(0.25)......括号中以2为除数类推。。。总结起来cordid 求arctan就是输入给定一个坐标(X,Y),通过这个表加或者减得到角度,与此同时X,Y也在加或者减,直到坐标的点Y为0,此时通过表的加减的和即为arctan的值

mobile02 发表于 2014-11-24 11:27:52

chenchaoting 发表于 2014-11-23 21:11
你说的是again 网友说的表么?那个表分别是arctan(1),arctan(0.5),arctan(0.25)......括号中以2为除数类推 ...

谢谢++
我想知道这个表是怎么产生的?是否能产生 1024的?
unsigned char code myangle[] =
    {
   /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64 */
      0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10,11,11,12,13,14,15,16,17,17,18,19,20,21,21,22,23,24,24,25,26,27,27,28,29,29,30,31,31,32,33,33,34,35,35,36,36,37,37,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45
    };

xiangyuan_122 发表于 2014-11-24 16:35:18

不错,收了
页: [1]
查看完整版本: 求ATAN2_16bit函数代码(最好是查表法)