Brain fade on basic trigonometry

Miscellaneous Forums/General Discussion/Brain fade on basic trigonometry

Simple one. You know how if you know an angle (0-360) and a radius you can work out the x and y coords of the edge or a circle e.g.

x = r * cos(angle)
y = r * sin(angle)

Well how to you go backwards to work the angle if you know the x and y? I know if it was a nice little right angled triangle WITH POSTITVE COORDS you'd go:

angle = acos(x/r)
or
angle = asin(y/r)

And you work out r as sqr(x*x+y*y). Well here's the problem, what if x or y are negative? Then when you work out r, r will always end up positive due the a minus*minus=positive. So it'll always give you angles in the postive quadrant.

Do you have to just work out which quadrant it's in and tweak the resulting angle by 90 degrees or whatever, or is there a better way, like with using Matrix maths?

Thanks!

What you need is Atan2(y2-y1,x2-x1).

x1,y1 = centre of circle
x2,y2 = point on edge of circle

As a side-note - anything that's gone through Sqr() always comes back as positive, too.

crap I knew there was a reason for ATan2!

Something else that just threw me. When you state an angle in a trigonometric circle it's taken from the positive X axis, in otherwords at 90 degress (3 o clock). So to translate into BMax rotation you have to subtract 90degrees from the result!

cough:-

http://www.syntaxbomb.com/forum/index.php/topic,50.0.html

Dabz

EDIT: Not sure if thats what you want grey

yeah but I've sorted it now. I see you used the 90 degree modification too. when does it go out of range then?

The fact that the numbers are always positive is actually a feature of the mathematical inverse functions... the answers are always given in only one quadrant, but there's the possibility that the answer you want is in another.

It's not a bug, it's a feature. Seriously.

P.S. How could calculators print out two answers if this wasn't the rule of the function?