计算没有标准函数或 C99 的 atan2 [英] Calculate atan2 without std functions or C99

查看:24
本文介绍了计算没有标准函数或 C99 的 atan2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 3 轴加速度计计算角度,但我的编译器没有 atan 或 atan2 函数.它有一个保留的内存插槽,但它调用了一个我在任何文件中都找不到的函数.

我的编译器是运行 ARMCC 编译器的 Keil µVision 4.编译有文件 math.h,但函数是 extern 并且不存在:

<块引用>

 extern _ARMABI double atan2(double/*y*/, double/*x*/);

是否有我可以包含实现了 arctan 函数的库或函数?或者是否有其他功能可以从加速度计计算角度?我需要对角度进行完整的 3 轴校准.

我希望避免一个充满预计算值的表格.

解决方案

实现自己的 arctan2 并不难.使用thisarctan2转换为arctana> 公式.然后您可以使用这个无限级数计算arctan.如果您对这个无穷级数的项数求和,您将非常接近库函数 arctan2 的作用.

这是一个类似的exp() 的实现,您可以将其用作参考.

I am calculating angles from a 3-axis accelerometer, but my compiler doesn't have a atan or atan2 function. It has a reserved memory slot, but it calls a function i can't find in any files.

My compiler is Keil µVision 4 running the ARMCC compiler. The compiles has the file math.h, but the function is extern and doesn't exist:

  extern _ARMABI double atan2(double /*y*/, double /*x*/);

Is there a lib or function I can include that has the function arctan implemented? Or is there an alternative function to calculate angles from accelerometer? I need full 3-axis calibration of the angles.

Edit: I was hoping to avoid a table full of pre-calculated values.

解决方案

Its not very difficult to implement your own arctan2. Convert arctan2 to arctan using this formula. And you can then calculate arctan using this infinite series. If you sum sufficient number of terms of this infinite series, you will get very close to what the library function arctan2 does.

Here is one similar implementation for exp() that you could use as a reference.

这篇关于计算没有标准函数或 C99 的 atan2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆