Languages
[Edit]
EN

JavaScript - Math.sin in degrees

5 points
Created by:
Root-ssh
177980

In JavaScript Math.sin() method works using radians by default. To switch it to degrees some simple operation is necessary ((Math.PI / 180) * degrees). In this article we can see custom Math.sin() function that works on degrees.

// ONLINE-RUNNER:browser;

function calculateSine(degrees) {
	var radians = (Math.PI / 180) * degrees;
  	return Math.sin(radians);
}


// Example:

console.log( calculateSine(0)   ); //  0
console.log( calculateSine(30)  ); // ~0.5
console.log( calculateSine(45)  ); //  0.7071067811865475
console.log( calculateSine(60)  ); //  0.8660254037844386
console.log( calculateSine(90)  ); //  1

console.log( calculateSine(180) ); // ~0
console.log( calculateSine(270) ); // -1
console.log( calculateSine(360) ); // ~0

See also

  1. JavaScript - Math.sin() method example
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - math (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join