Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 109e4a6

Browse files
algorithm: find length of an arc and area of the sector formed by an arc of a circle (#1119)
* Add an algorithm to find length and area of an arc of a circle * Updated to follow Javascript Standard Style * Update CircularArc.js * Update CircularArc.js * Add tests * Followed Javascript standard style
1 parent 8461271 commit 109e4a6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

‎Maths/CircularArc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { degreeToRadian } from './DegreeToRadian.js'
2+
3+
/**
4+
* @function circularArcLength
5+
* @description calculate the length of a circular arc
6+
* @param {Integer} radius
7+
* @param {Integer} degrees
8+
* @returns {Integer} radius * angle_in_radians
9+
* @see https://en.wikipedia.org/wiki/Circular_arc
10+
* @example circularArcLength(3, 45) = 2.356194490192345
11+
*/
12+
function circularArcLength (radius, degrees) {
13+
return radius * degreeToRadian(degrees)
14+
}
15+
/**
16+
* @function circularArcArea
17+
* @description calculate the area of the sector formed by an arc
18+
* @param {Integer} radius
19+
* @param {Integer} degrees
20+
* @returns {Integer} 0.5 * r * r * angle_in_radians
21+
* @see https://en.wikipedia.org/wiki/Circular_arc
22+
* @example circularArcArea(3,45) = 3.5342917352885173
23+
*/
24+
function circularArcArea (radius, degrees) {
25+
return Math.pow(radius, 2) * degreeToRadian(degrees) / 2
26+
}
27+
28+
export {
29+
circularArcLength,
30+
circularArcArea
31+
}

‎Maths/test/CircularArc.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { circularArcLength, circularArcArea } from '../CircularArc'
2+
3+
describe('circularArcLength', () => {
4+
it('with natural number', () => {
5+
const arcLengthOfOneThirty = circularArcLength(1, 30)
6+
const arcLengthOfThreeSixty = circularArcLength(3, 60)
7+
expect(arcLengthOfOneThirty).toBe(0.5235987755982988)
8+
expect(arcLengthOfThreeSixty).toBe(3.141592653589793)
9+
})
10+
})
11+
12+
describe('circularArcArea', () => {
13+
it('with natural number', () => {
14+
const arcAreaOfOneThirty = circularArcArea(1, 30)
15+
const arcAreaOfThreeSixty = circularArcArea(3, 60)
16+
expect(arcAreaOfOneThirty).toBe(0.2617993877991494)
17+
expect(arcAreaOfThreeSixty).toBe(4.71238898038469)
18+
})
19+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /