发新帖我要提问
12
返回列表
打印

角度计算求助

[复制链接]
楼主: 耕在此行
手机看帖
扫描二维码
随时随地手机跟帖
21
s46410864| | 2009-7-25 11:17 | 只看该作者 回帖奖励 |倒序浏览

还有..

你这个角度要求也不高,只有0.1,我记得那个表角度到0.001,你这个只要0-90度,做个表吧,没多少

使用特权

评论回复
22
耕在此行|  楼主 | 2009-7-25 13:40 | 只看该作者

呵呵 27 28 29楼

查表本人也想过,一想到要用到很多字节,就有点省不得了.
再加上原来印象中有那么一个泰勒公式,所以一直想用公式来计算.

30楼的公式,还有点不明白,x^3是3的三次方吧.一般项是什么,(不好意思,时间久了,高数都差不多忘光了.

31楼,呵呵 本人也确实不小了.

使用特权

评论回复
23
s46410864| | 2009-7-25 13:58 | 只看该作者

哎呀 大哥......

X^3是3次方..那个一般项,那个展开项的表达式..要几就有几,
我觉得你那个0.1的精度,有那么3~5项也就差不多了,

使用特权

评论回复
24
耕在此行|  楼主 | 2009-7-25 14:06 | 只看该作者

谢谢楼上的指点

但一般项公式还是有点搞不清楚计算顺序.
能否帮忙按混合运算写得再明晰些不.

使用特权

评论回复
25
s46410864| | 2009-7-25 14:43 | 只看该作者

是这样的

 "(2n)!/[2^{2n}(n!)^2]" * "x^{2n+1}"/(2n+1)
引号中的是一项
例一下:如n=2;(也就是第三项); 
{(2*3*4)/[(2^4)*2^2]  *  X^5 }/5=(12/16*4*5)*X^5
=(3/40)x^5 ;也就是说,最后的那个2N+1
能拿到前面来,就是  :
"(2n)!/[{2^(2n)}{(n!)^2}*(2n+1)]" * "x^{2n+1}"
这样子了,

使用特权

评论回复
26
itelectron| | 2009-7-25 16:42 | 只看该作者

晕到知道的就直接说!俺是技校的 帮不上忙咯

可以下个工具

使用特权

评论回复
27
itelectron| | 2009-7-25 16:45 | 只看该作者

Atan

/********************************************************************************
* File Name : tfr16.c                                                           *
*                                                                               *
* Function : Frac16 tfr16AtanOverPI     (Frac16 x)                              *
*                                                                               *
* Description:                                                                  *
* This routine computes the Arctan function of fractional input value x, and    *
* divides that result by pi i.e. Arctan(x)/pi.                                  *
*                                                                               *
* Inputs :                                                                      *
*          1) x - input data value                                              *
*                                                                               *
* Outputs :                                                                     *
*          1) z - Arctan(x)/pi                                                  *
*                                                                               *
* Algorithm:                                                                    *
* AtanOverPI(x) = 0.5 - AsinOverPI(sqrt(1-x^2)/sqrt(1-x^4))                     *
********************************************************************************/

Frac16 tfr16AtanOverPI  (Frac16 x)
{
    Frac16 z, z1, z2, sign_flag = 0;


  if(x < 0)
    {
        sign_flag = 1;
        x = negate(x);
    }

    if ( x == CFF(1))
    {
        z = CFF(0.25000000000000);
    }
    else
    {
        z1 = mult_r(x,x);   /* z1 = x^2 */
    if (z1 > 0)
         z1 = add(z1,1); /* To compensate the precision lost while calculating square */

        z2 = mult_r(z1,z1);   /* z2 = x^4 */
        if (z2 > 0)
           z2 = add(z2,1); /* To compensate the precision lost while calculating square */


        z1 = mfr16Sqrt(sub(CFF(1),z1));  /* z1 = sqrt(1-x^2) */
        z2 = mfr16Sqrt(sub(CFF(1),z2));  /* z2 = sqrt(1-x^4) */
        x = div_s(z1,z2);                /* x = (sqrt(1-x^2)/sqrt(1-x^4)) */

        /* AtanOverPI(x) = 0.5 - AsinOverPI(sqrt(1-x^2)/sqrt(1-x^4)) */
        z = sub(CFF(0.5),tfr16AsinOverPI(x));
    }

   if (sign_flag == 1)
    {
        z = negate(z);
    }
  return z;
}

使用特权

评论回复
28
itelectron| | 2009-7-25 16:48 | 只看该作者

2

#define CFF(x) (Frac16)(x * 32767.0)


inline Word16 negate(register Word16 svar1)
{

    asm(.optimize_iasm on);
    asm(neg svar1);
    asm(.optimize_iasm off);
    return svar1;
}

使用特权

评论回复
29
itelectron| | 2009-7-25 16:56 | 只看该作者

定点计算 可以左移 右移!



/********************************************************************************
* File Name : tfr16.c                                                           *
*                                                                               *
* Function : Frac16 tfr16ASinOverPI     (Frac16 x)                              *
*                                                                               *
* Description:                                                                  *
* This routine computes the Arcsin function of fractional input value x, and    *
* divides that result by pi i.e. Arcsin(x)/pi.                                  *
*                                                                               *
* Inputs :                                                                      *
*          1) x - input data value                                              *
*                                                                               *
* Outputs :                                                                     *
*          1) z - Arcsin(x)/pi                                                  *
*                                                                               *
* Algorithm:                                                                    *
*           if(x >= 0.70710678118655)                                           *
*              z = 0.5 - ASinOverPI(sqrt(1-x^2))                                *
*           else                                                                *
*              z = ASinOverPI(x)                                                *
*                                                                               *
* Where :                                                                       *
* ASinOverPI(x) = x(AsineCoefs(0)+x^2(AsineCoefs(1)+x^2(AsineCoefs(2)+          *
*                 x^2(AsineCoefs(3)+x^2(AsineCoefs(4)+x^2(AsineCoefs(5)+        *
*                 x^2(AsineCoefs(6)+AsineCoefs(7)x^2)))))))                     *
*                                                                               *
********************************************************************************/

Frac16 tfr16AsinOverPI  (Frac16 x)
{
    Frac16   z, temp16, sign_flag = 0, i, thres_flag = 0;
    Frac32   Acc = 0;

    if (x < 0)
    {
        sign_flag = 1;
        x = negate(x);
    }

  z = mult_r(x,x);
    if (x > Inv_Threshold)
    {
        thres_flag = 1;
        x = mfr16Sqrt(sub(CFF(1),add(z,1)));
        z = mult_r(x,x);
    }

  temp16 = AsineCoefs[7];

    for(i = 6; i >= 0; i--)
    {
        Acc = L_deposit_h(AsineCoefs);
      temp16 =  mac_r(Acc,temp16,z);
    }

    z = mult_r(temp16,x);

    if (thres_flag == 1)
    {
        z = sub(CFF(0.5),z);
    }

    if (sign_flag == 1)
    {
        z = negate(z);
    }

  return z;
}

使用特权

评论回复
30
itelectron| | 2009-7-25 16:58 | 只看该作者

3

inline Word32 __L_deposit_h(register Word16 ssrc)
{

    register Word32 ldst;
    asm(.optimize_iasm on);
    asm(/*    .iasm_sideeffects off;*/.iasm_reg2regsetcopyflag off;
        move.w ssrc,ldst;
        /*.iasm_sideeffects on; */    .iasm_reg2regsetcopyflag on);
    asm(.optimize_iasm off);
    return ldst;
}

使用特权

评论回复
31
itelectron| | 2009-7-25 17:01 | 只看该作者

子函数XXX

const Frac16 SineCoefs[] =  {
                             CFF(0.39269908169872),
                             CFF(-0.64596409750625),
                             CFF(0.31877050498467),
                             CFF(-0.07446482317004),
                             CFF(0.01026823582639),
                             CFF(-0.00092130386821),
                             CFF(0.00005828785072)
                            };
const Frac16 AsineCoefs[] = {
                             CFF(0.31830988618379),
                             CFF(0.05305164769730),
                             CFF(0.02387324146378),
                             CFF(0.01421026277606),
           CFF(0.00967087327815),
           CFF(0.00712127941391),
           CFF(0.00552355646848),
           CFF(0.00444514782464)
          };

使用特权

评论回复
32
itelectron| | 2009-7-25 17:12 | 只看该作者

...

使用特权

评论回复
33
耕在此行|  楼主 | 2009-7-25 18:20 | 只看该作者

楼上的两位 感谢你们啦

我好好看看.

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则