Skip to content

Instantly share code, notes, and snippets.

@veganben
Created December 10, 2012 11:29
Show Gist options
  • Save veganben/4250095 to your computer and use it in GitHub Desktop.
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.
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