Created
December 10, 2012 11:29
-
-
Save veganben/4250095 to your computer and use it in GitHub Desktop.
When you want to calculate an angle given the opposite and adjacent sides, there are multiple possible values. This gist calculates the one you really wanted all along.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Math.correctInverseTan = function(x,y){ | |
| var θ = Math.atan(y / x); | |
| if(x < 0){ | |
| θ += Math.PI; | |
| } else { | |
| if(y < 0){ | |
| θ += 2*Math.PI; | |
| } | |
| } | |
| return θ; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment