Trigonometry Java

Hello all

I’m making a 2D side-scroller … really simple with paint-graphics.
Right now you can shoot “lazers” forward, but I’d like them to go after a mousePressed

So, I’ve made it work so far that I’ve got the mousePressed X and Y, now I want a angle so that I can change the y-position of the “lazor” (;D) after the angle, this is my approach showed with paint-skills:

http://u.snelhest.org/i/2011/02/05_292.JPG

This is how I would calculate the V on my calculator … Is there a function like the “tan-1” in Java? (I can’t seem to find any when googling)
If not - what to use?

Thanks for answers
And sorry if I choose the wrong forum section :stuck_out_tongue:

//M

Use Math.atan2( y, x ). It’ll handle the division of mY over mX (and the attendant risk of divide-by-zero) for you. Note the order of arguments though - it’s very easy to get used to entering the x value as the first argument when doing geometry stuff.

Thanks for the help, great :wink:
It seems to do what I wanted :slight_smile: