不使用 std 函数或 C99 计算 atan2 [英] Calculate atan2 without std functions or C99

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

问题描述

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

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

<块引用>

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

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

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

解决方案

实现自己的arctan2并不难.使用 this 将 arctan2 转换为 arctan一个>公式.然后,您可以使用此 infinite series 计算 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.

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

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