Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the opposite of a direction angle (360 degrees) in JavaScript

The following question: https://math.stackexchange.com/questions/1319615/how-to-calculate-opposite-direction-angle shows the formula for doing this. How would I write this: (α+180) mod 360 in javascript. (a is a variable)

like image 327
urwoi Avatar asked Dec 06 '25 18:12

urwoi


1 Answers

You should use the % operator:

var angle = 210;
var oppositeAngle = (angle + 180) % 360;
console.log(oppositeAngle);
like image 108
Alberto Trindade Tavares Avatar answered Dec 08 '25 10:12

Alberto Trindade Tavares



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!