# Joystick to angle / atan2 crash

Hi, i would like to convert a joystick's x.y coord. into an angle. X and Y range from -.5 to .5 . Both values are set to non-zero.

I'm using a math expr. patch with this formula:

atan2 (x / y) / ( PI / 180)

however, atan2 keeps crashing.

any ideas on how to get an angle from x.y coords ? thanks

## Comment viewing options

### Re: Joystick to angle / atan2 crash

if memory serves, atan is the one flaw of the mathexp patch.

javascript patch will work, remember the units are different (rads / degs)

### Re: Joystick to angle / atan2 crash

Is it a situation where you can use put whatever it is in a 3D transform and just do the appropriate math for the x- hook to the x rotation, do the math you want for the y, hook to the y rotation... so that in a sense the 3D transform does the work for you?

I do that all the time and it can work effectively for certain uses... I just take the x coord, and multiply by 90, 180, 360 (depending on what I want the "throw/sensitivity" to be).... and do the same for the y, hook it up to a 3D transform. Simple math/multiplication setup.

Sorry if that doesn't wind up helping you any... I'm also going to be attempting some joystick stuff shortly, and if I have any real revelations I'll share them.

(on a side note, I finally broke down and bought a pretty good javascript reference, and all I can say is I wish I had bought it sooner.)

### Re: Joystick to angle / atan2 crash

What Javascript reference? I bought one a few years ago but it is bogged down in HTML/Web uses so doesn't get gritty in the right places.

### Re: Joystick to angle / atan2 crash

Oh, it's nothing really QC centric... Javascript has really found it's niche with web stuff, so I wasn't particularly expecting any not to have crap about html, ajax, etc. There was an extremely thick tomb of info I almost got, and every book (out of the 4 or 5) looked like it had basically the same info. I ended up getting "The Missing Manual" as much for its simplistic outline than anything else.

I'll be frank... there is NOTHING I haven't looked at in that book in some other form. There were a couple of specific examples that pertained to some things I'm working on, and the explanations were immediately understandable, so I was like "screw it". I kinda wrestle with picking up books like that since so much good stuff is on the web.

I feel like it's the math behind any type of code language that makes it gritty or not. Since most of the javascript books are web-centric, by the time it gets into the more complex examples, it is all "web stuff". It's up to us to find ways to "gritify" it for QC.

### Re: Joystick to angle / atan2 crash

Yes. Agreed. Just wish my maths was stronger, it's been a while... even a little maths goes a long way in visual environment like QC though. Also there are lots of tricks Comp Sci students obviously learn re algorithms and the smart way to approach a problem. I just battle through the worst options first but perhaps that's stronger than 'book learning' in the end!?