資源簡介
atan2的查表法實(shí)現(xiàn),支持宏定義調(diào)整精度,非常適合沒有帶FPU的MCU使用。

代碼片段和文件信息
//?ConsoleApplication4.cpp?:?定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
typedef?float?float32_t;
#ifndef?M_PI
#define?M_PI?3.14159265358979323846
#endif
#include?“atan2_tab.h“
int?main()
{
atan2_tab_init();
double?res_lib;
double?res_tab;
#define?LUT_NUM 4096
#define PRICISION 0.001
for?(int?i?=?0;?i? {
//第一象限
res_lib?=?atan2(i?(LUT_NUM?-?1));
res_tab?=?atan2_tab_calc(i?(LUT_NUM?-?1));
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第一象限x=%d?y=%d\n?diff:%.5f“?(LUT_NUM?-?1)?i?fabs(res_lib?-?res_tab));
}
res_lib?=?atan2((LUT_NUM?-?1)?i);
res_tab?=?atan2_tab_calc((LUT_NUM?-?1)?i);
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第一象限x=%d?y=%d?diff:%.5f\n“?i?(LUT_NUM?-?1)?fabs(res_lib?-?res_tab));
}
//第二象限
res_lib?=?atan2(i?-(LUT_NUM?-?1));
res_tab?=?atan2_tab_calc(i?-(LUT_NUM?-?1));
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第二象限x=%d?y=%d?diff:%.5f\n“?-(LUT_NUM?-?1)?i?fabs(res_lib?-?res_tab));
}
res_lib?=?atan2((LUT_NUM?-?1)?-i);
res_tab?=?atan2_tab_calc((LUT_NUM?-?1)?-i);
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第二象限x=%d?y=%d?diff:%.5f\n“?-i?(LUT_NUM?-?1)?fabs(res_lib?-?res_tab));
}
//第三象限
res_lib?=?atan2(-i?-(LUT_NUM?-?1));
res_tab?=?atan2_tab_calc(-i?-(LUT_NUM?-?1));
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第三象限x=%d?y=%d?diff:%.5f\n“?-(LUT_NUM?-?1)?-i?fabs(res_lib?-?res_tab));
}
res_lib?=?atan2(-(LUT_NUM?-?1)?-i);
res_tab?=?atan2_tab_calc(-(LUT_NUM?-?1)?-i);
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“第三象限x=%d?y=%d?diff:%.5f\n“?-i??-(LUT_NUM?-?1)?fabs(res_lib?-?res_tab));
}
//第四象限
res_lib?=?atan2(-i?(LUT_NUM?-?1));
res_tab?=?atan2_tab_calc(-i?(LUT_NUM?-?1));
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“1第四象限x=%d?y=%ddiff:%.5f\n“?(LUT_NUM?-?1)?-i?fabs(res_lib?-?res_tab));
}
res_lib?=?atan2(-(LUT_NUM?-?1)?i);
res_tab?=?atan2_tab_calc(-(LUT_NUM?-?1)?i);
if?(fabs(res_lib?-?res_tab)?>?PRICISION)
{
printf(“2第四象限x=%d?y=%d?diff:%.5f\n“?-i?(LUT_NUM?-?1)?fabs(res_lib?-?res_tab));
res_lib?=?atan2(-(LUT_NUM?-?1)?i);
res_tab?=?atan2_tab_calc(-(LUT_NUM?-?1)?i);
}
res_lib?=?atan2((LUT_NUM?-?1)?-4094);
res_tab?=?atan2_tab_calc((LUT_NUM?-?1)?-4094);;
res_lib?=?atan2(-(LUT_NUM?-?1)?208);
res_tab?=?atan2_tab_calc(-(LUT_NUM?-?1)?208);
}
system(“pause“);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2866??2018-10-13?18:45??atan2_lut_test.cpp
?????文件????????2404??2018-10-13?18:39??atan2_tab.cpp
?????文件?????????822??2018-10-13?18:39??atan2_tab.h
- 上一篇:室內(nèi)定位技術(shù)論文
- 下一篇:ecshop分類按拼音索引
評論
共有 條評論