0

I'm sorry for such basic question, but I'm trying to implements two finger rotation on Android and I found several post here on SO, trying to make sense of them I couldn't understand why sometimes the result of atan2 is considered between -Pi and Pi and sometimes 0, 360 or -180, 180.

I really can't understand this: https://stackoverflow.com/a/10682187/1692502 where the user perform a modulo %360 on a result that's supposed to be < 3.14...

thanks

Community
  • 1
  • 1
datamosh
  • 130
  • 3
  • 10
  • 2
    I think the respondent assumed that the asker already knew how to convert radians to degrees, as there was a call to `Math.toDegrees` in the question. – Dawood ibn Kareem Nov 26 '13 at 00:34
  • I read the answer ... their answer defines some methods that assume their arguments are in degrees, but this isn't "wrong" because the answer doesn't show these methods being used on an `atan2` result. It doesn't show the methods being used at all. I think they were assuming that their arguments would be degrees and you would use `Math.toDegrees` before calling them, but some comments would have been nice. – ajb Nov 26 '13 at 00:35

2 Answers2

3

Assuming you don't understand the difference of 360° and 2 Pi: There are different ways to express a distance on a circle's perimeter. An angle of 0° to 360° is probably the most common one, but in scientific notation, it is more common to use radians - which is a distance on the perimeter of the unit circle.

If you think of the unit circle (a circle with radius 1), you'll notice the perimeter is 2 Pi. If you only go around half the circle, the perimeter of that would be Pi - and you went from 0° to 180°. So all the notations that you mentioned in your question actually mean the same, just expressed in a different way.

atan2 returns a value between -Pi and +Pi (which covers 2 Pi and is thus a full circle) that can easily be converted to degrees using Math.toDegrees()

user207421
  • 305,947
  • 44
  • 307
  • 483
fpw
  • 801
  • 4
  • 12
0

From the Javadoc for atan2:

public static double atan2(double y, double x)

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.

not sure where the confusion lies (it seems the linked SO Answer is wrong)

rolfl
  • 17,539
  • 7
  • 42
  • 76
  • I don't find it wrong, just ambiguous. It doesn't say what the numbers that are passed into that `ClipAngleTo0_360` method are supposed to be. – Dawood ibn Kareem Nov 26 '13 at 00:35
  • Hmm... I am agreeing with you. The refernced answer is a mix of C and Java. I believe the clip is supposed to be applied to the input values, not the output. – rolfl Nov 26 '13 at 00:36