Mr RB
Well-Known Member
Hi, does anyone know a fast easy way to derive an angle; 0-359 degrees from signed XY values?
Examples;
X 10, Y 10 = 45'
X 0, Y 7 = 0'
X-40, Y 20 = 334'
I can use 32bit math multiply and divides etc as I have already used these in the project so the ROM for these functions is already used, but ideally it should not take too many cycles and not use too much ROM to do the angle calc.
The good news is it only needs the angle as an integer 0 - 359 and an error of 2' or 3' is acceptable, so it doesn't need trig math.
The XY values are signed 16bit values, although if needed I can scale these down to signed 8bit values if it gives enough saving in speed or ROM.
If anyone has a clever angle kludge that gets me within 2 degrees of the right answer please speak up!
Examples;
X 10, Y 10 = 45'
X 0, Y 7 = 0'
X-40, Y 20 = 334'
I can use 32bit math multiply and divides etc as I have already used these in the project so the ROM for these functions is already used, but ideally it should not take too many cycles and not use too much ROM to do the angle calc.
The good news is it only needs the angle as an integer 0 - 359 and an error of 2' or 3' is acceptable, so it doesn't need trig math.
The XY values are signed 16bit values, although if needed I can scale these down to signed 8bit values if it gives enough saving in speed or ROM.
If anyone has a clever angle kludge that gets me within 2 degrees of the right answer please speak up!