Sign in to follow this  
beyondtron

Writing a Fixed Point atan2 Function

Recommended Posts

beyondtron    122
I need to develop an math.h like atan2() function in C using fixed point integer math. I know this is definitely possible as I've seen places that do have fixed point atan2 functions such as MathFP for Java and Allegro's fixatan2(fixed y, fixed x). Can anyone guide me on the best way to implement such a function, I've done a little research and I've found the Maclaurin series, just wondering if this is the best way or if there are alternatives (or even source to a fixed point implementation of atan2). Thanks for any help!

Share this post


Link to post
Share on other sites
Nomad010    304
I have no idea what you just said, but I am assuming you want to develop a function to work out the arc-tan of a fixed point. I don't know if this will help, but it could help to learn the simple trig identities(if you don't know them already) and learn the trig rules such as the Sine Rule and the Cosine Rule.

Share this post


Link to post
Share on other sites
beyondtron    122
Thanks for the reply.

I'm not trying to figure out the arctan of a fixed point, but rather trying to develop a function to find the arc tangent of y/x much like the C function in the Math.h library atan2(y,x).

I am developing this function using fixed point arithmetic, ie. no decimals (floating point values). My question is really what is the best method or algorithm to calculate the arctangent of y/x without using a scientific calculator's arctan button?

Share this post


Link to post
Share on other sites
Charles B    863
The context in which you need such advanced math in fixed point and the bits of precision required would help. Anyway there are 4 tracks that might guide you :
- lut (look up tables) can surely boost fixed point since many muls and divs are not welcome.
- Taylor series or Newton-Raphson like technics (based on limited developments).
- Approximate another function, quicker to compute. Then get back what you want. For instance I have found this very bright link recently about
acos
- Then SIMD (MMX/3DNow, MMX/SSE or SSE2/SSE) that combine integer and floating points are very probably the most efficient ways to input and ouput fixed points.

Even with standard code do not neglect floating point in temporary code à priori, unless your chip does not have a FPU.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this