diff --git a/src/algorithms/math/radian/README.md b/src/algorithms/math/radian/README.md new file mode 100644 index 00000000..2de4655e --- /dev/null +++ b/src/algorithms/math/radian/README.md @@ -0,0 +1,36 @@ +# Radian + +The **radian** (symbol **rad**) is the unit for measuring angles, and is the +standard unit of angular measure used in many areas of mathematics. + +The length of an arc of a unit circle is numerically equal to the measurement +in radians of the angle that it subtends; one radian is just under `57.3` degrees. + +An arc of a circle with the same length as the radius of that circle subtends an +angle of `1 radian`. The circumference subtends an angle of `2π radians`. + +![Radian](https://upload.wikimedia.org/wikipedia/commons/4/4e/Circle_radians.gif) + +A complete revolution is 2π radians (shown here with a circle of radius one and +thus circumference `2π`). + +![2 pi Radian](https://upload.wikimedia.org/wikipedia/commons/6/67/2pi-unrolled.gif) + +**Conversions** + +| Radians | Degrees | +| :-----: | :-----: | +| 0 | 0° | +| π/12 | 15° | +| π/6 | 30° | +| π/4 | 45° | +| 1 | 57.3° | +| π/3 | 60° | +| π/2 | 90° | +| π | 180° | +| 2π | 360° | + + +## References + +- [Wikipedia](https://en.wikipedia.org/wiki/Radian) diff --git a/src/algorithms/math/radian/__test__/degreeToRadian.test.js b/src/algorithms/math/radian/__test__/degreeToRadian.test.js new file mode 100644 index 00000000..71a14d05 --- /dev/null +++ b/src/algorithms/math/radian/__test__/degreeToRadian.test.js @@ -0,0 +1,12 @@ +import degreeToRadian from '../degreeToRadian'; + +describe('degreeToRadian', () => { + it('should convert degree to radian', () => { + expect(degreeToRadian(0)).toBe(0); + expect(degreeToRadian(45)).toBe(Math.PI / 4); + expect(degreeToRadian(90)).toBe(Math.PI / 2); + expect(degreeToRadian(180)).toBe(Math.PI); + expect(degreeToRadian(270)).toBe(3 * Math.PI / 2); + expect(degreeToRadian(360)).toBe(2 * Math.PI); + }); +}); diff --git a/src/algorithms/math/radian/__test__/radianToDegree.test.js b/src/algorithms/math/radian/__test__/radianToDegree.test.js new file mode 100644 index 00000000..b6fe7a12 --- /dev/null +++ b/src/algorithms/math/radian/__test__/radianToDegree.test.js @@ -0,0 +1,12 @@ +import radianToDegree from '../radianToDegree'; + +describe('radianToDegree', () => { + it('should convert radian to degree', () => { + expect(radianToDegree(0)).toBe(0); + expect(radianToDegree(Math.PI / 4)).toBe(45); + expect(radianToDegree(Math.PI / 2)).toBe(90); + expect(radianToDegree(Math.PI)).toBe(180); + expect(radianToDegree(3 * Math.PI / 2)).toBe(270); + expect(radianToDegree(2 * Math.PI)).toBe(360); + }); +}); diff --git a/src/algorithms/math/radian/degreeToRadian.js b/src/algorithms/math/radian/degreeToRadian.js new file mode 100644 index 00000000..fb3836cd --- /dev/null +++ b/src/algorithms/math/radian/degreeToRadian.js @@ -0,0 +1,7 @@ +/** + * @param {number} degree + * @return {number} + */ +export default function degreeToRadian(degree) { + return degree * (Math.PI / 180); +} diff --git a/src/algorithms/math/radian/radianToDegree.js b/src/algorithms/math/radian/radianToDegree.js new file mode 100644 index 00000000..e733f415 --- /dev/null +++ b/src/algorithms/math/radian/radianToDegree.js @@ -0,0 +1,7 @@ +/** + * @param {number} radian + * @return {number} + */ +export default function radianToDegree(radian) { + return radian * (180 / Math.PI); +}