ATAN2 in calculated questions

ATAN2 in calculated questions

by Tim Lovett -
Number of replies: 2

MoodleDocs says...

ATAN2: Arc tangent of two variables -- pass in two values like (x, y), and you'll get the atah(y/x), adjusted to the proper quadrant.

Checking the quadrant to see if it matches Excel's ATAN2... It looks to me like Excel's ATAN2(x,y) is Moodle ATAN2(y,x)...

rad2deg(atan2({x},{y}))
rad2deg(atan2((-4.0),3.0)) = -53.13
Correct answer : -53.13 inside limits of true value rad2deg(atan2({x},{y}))
Min: -53.661403377698 --- Max: -52.598801330614

This would have been 2nd quad in Excel

rad2deg(atan2({x},{y}))
rad2deg(atan2(2.1,(-7.6))) = 164.55
Correct answer : 164.55 inside limits of true value rad2deg(atan2({x},{y}))
Min: 162.90814679598 --- Max: 166.19922046863
This would have been 4th quad in Excel

I'd prefer matching Excel, but is Moodle docs wrong here?

Average of ratings: -
In reply to Tim Lovett

Re: ATAN2 in calculated questions

by Pierre Pichet -

First take a look at the PHP atan() function which is the one used.

If you conclude that the info is wrong then you can change the moodle corresponding doc.

Docs are build by peoples like you who check them closely.wink

Pierre

P.S. you could look at the history to pinpoint when and who wrote this comment.

In reply to Pierre Pichet

Re: ATAN2 in calculated questions

by Tim Lovett -

Yeah - I'm getting a bit more support for PHP ATAN2(y,x) being the reverse of Excel's ATAN2(x,y):

This is from: http://www.php.net/manual/en/function.atan2.php

float atan2 ( float $y , float $x )

This function calculates the arc tangent of the two variables x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result.

The function returns the result in radians, which is between -PI and PI (inclusive).