mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Add Radian.
This commit is contained in:
parent
b3315966e5
commit
096d5a8b5b
36
src/algorithms/math/radian/README.md
Normal file
36
src/algorithms/math/radian/README.md
Normal file
@ -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)
|
12
src/algorithms/math/radian/__test__/degreeToRadian.test.js
Normal file
12
src/algorithms/math/radian/__test__/degreeToRadian.test.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
12
src/algorithms/math/radian/__test__/radianToDegree.test.js
Normal file
12
src/algorithms/math/radian/__test__/radianToDegree.test.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
7
src/algorithms/math/radian/degreeToRadian.js
Normal file
7
src/algorithms/math/radian/degreeToRadian.js
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @param {number} degree
|
||||
* @return {number}
|
||||
*/
|
||||
export default function degreeToRadian(degree) {
|
||||
return degree * (Math.PI / 180);
|
||||
}
|
7
src/algorithms/math/radian/radianToDegree.js
Normal file
7
src/algorithms/math/radian/radianToDegree.js
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @param {number} radian
|
||||
* @return {number}
|
||||
*/
|
||||
export default function radianToDegree(radian) {
|
||||
return radian * (180 / Math.PI);
|
||||
}
|
Loading…
Reference in New Issue
Block a user