How to calculate arctan(x)?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to calculate arctan(x)?

跳至解决方案
2,352 次查看
aaronlee
Contributor V

How to calculate arctan(x), sin(x), cos(x) in S12ZVCA ?

 

Best Regards,

Aaron

标记 (1)
0 项奖励
回复
1 解答
2,345 次查看
lama
NXP TechSupport
NXP TechSupport

Hi,

you can use standard CodeWarrior library functions. however they are relatively (depends on application) slow:

#include <math.h>

double atan(double x);

float atanf(float x);

long double atanl(long double x);

 

Another possibility is to use math and control library which uses fractional arithmetics and polynomial substitution of the functions:

 

Search for mc9s12zvm_ammclib at nxp.com to get more info or

https://www.nxp.com/design/automotive-software-and-tools/nxp-automotive-math-and-motor-control-libra...

to download. (you must press "more" to find library in collapsed list)

 

Best regards,

Ladislav

 

 

 

The last possibility is to use own searching table...depends on required precisiion.

 

在原帖中查看解决方案

0 项奖励
回复
3 回复数
2,346 次查看
lama
NXP TechSupport
NXP TechSupport

Hi,

you can use standard CodeWarrior library functions. however they are relatively (depends on application) slow:

#include <math.h>

double atan(double x);

float atanf(float x);

long double atanl(long double x);

 

Another possibility is to use math and control library which uses fractional arithmetics and polynomial substitution of the functions:

 

Search for mc9s12zvm_ammclib at nxp.com to get more info or

https://www.nxp.com/design/automotive-software-and-tools/nxp-automotive-math-and-motor-control-libra...

to download. (you must press "more" to find library in collapsed list)

 

Best regards,

Ladislav

 

 

 

The last possibility is to use own searching table...depends on required precisiion.

 

0 项奖励
回复
2,140 次查看
aaronlee
Contributor V

Share my code "Clockwise Rotation"

 from (A, B) to (X,Y)

 

#include "math.h"

double atan(double);
float atanf(float);

int16_t iA, iB, iX, iY;
float fAngle, fDistance, fRotate;

fAngle = atan2f (iB, iA);
fDistance = sqrt(pow(iA,2) + pow(iB,2));
iX = fDistance * cos(fAngle - fRotate);
iY = fDistance * sin(fAngle - fRotate);

 

Best Regards,

Aaron

 

Reference:

Determining clockwise vs counter clockwise rotations

Determining angle of rotation

0 项奖励
回复
2,338 次查看
aaronlee
Contributor V

Hi Ladislav,

Very useful. Thank you.

Best Regards,

Aaron

0 项奖励
回复