# Finding an angle from a Joystick (x and y value)

Hi, I am currently developing a robot with the Wii nunchuck and I am trying to find a way to deduce the angle in degree that forms my x and y value with the center of the joystick. I though of a way using the atan() method but It will only work for angle bigger than 45 degree (since it works with the Pythagorean theorem and the triangle whose 3 angle must be equal 180).

So let's say i have my coord ( 28, 5 ) , I want to be able to find what angle it forms from the point 0,0, clockwise... where point (1,0) would be 0 , (1,1) would be 45, (0,1) would be 90 and so on...

I am really looking forward to your answers...

Thanks a lot !!

I haven't used this and I think some of the data structures will have to be recreated as they don't seem to be online, but this is a really neat description of how to solve your problem for underpowered 8 bit microprocessors: www.cypress.com/?docID=2279

maybe someone's done it with an arduino already

Hi, I am currently developing a robot with the Wii nunchuck and I am trying to find a way to deduce the angle in degree that forms my x and y value with the center of the joystick. I though of a way using the atan() method but It will only work for angle bigger than 45 degree

That's exactly what atan2(x, y) is for.

+1 for using atan2

I used this until I ran short of cycles, then I switched to an approximation of atan2. Less accurate, but more than accurate enough for the work I was doing.

Works great with atan2() !! Thanks a lot !!

How did you do your approximation of atan2() ? Only curious !! I dont think I am running out of cycle (though I dont really know what this mean... care to explain?).

Thanks a lot for the fast answer !