Converting Between Degrees and Radians - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Converting Between Degrees and Radians - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, December 22, 2018

Converting Between Degrees and Radians

Converting Between Degrees and Radians


Problem

You have an angle in degrees. To use the value in the Math object’s trigonometric func‐ tions, you need to convert the degrees to radians. 

Solution

To convert degrees to radians, multiply the value by (Math.PI / 180):


var radians = degrees * (Math.PI / 180);



To convert radians to degrees, multiply the value by (180 / Math.PI):


var degrees = radians * (180 / Math.PI);


EXPLAIN

All Math trigonometric methods (sin(), cos(), tin(), asin(), acos(), atan(), and atan2()), take values in radians, and return radians as a result.

Yet it’s not unusual for people to provide values in degrees rather than radians, as degrees are the more familiar unit of measure.

he functionality covered in the solution provides the conversion between the two units. 

No comments:

Post a Comment

Post Top Ad