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

Add an algorithm to find length of an arc and area of the sector formed by an arc of a circle #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
raklaptudirm merged 6 commits into TheAlgorithms:master from prashalruchiranga:prashal-1
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Maths/CircularArc.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { degreeToRadian } from './DegreeToRadian.js'

/**
* @function circularArcLength
* @description calculate the length of a circular arc
* @param {Integer} radius
* @param {Integer} degrees
* @returns {Integer} radius * angle_in_radians
* @see https://en.wikipedia.org/wiki/Circular_arc
* @example circularArcLength(3, 45) = 2.356194490192345
*/
function circularArcLength (radius, degrees) {
return radius * degreeToRadian(degrees)
}
/**
* @function circularArcArea
* @description calculate the area of the sector formed by an arc
* @param {Integer} radius
* @param {Integer} degrees
* @returns {Integer} 0.5 * r * r * angle_in_radians
* @see https://en.wikipedia.org/wiki/Circular_arc
* @example circularArcArea(3,45) = 3.5342917352885173
*/
function circularArcArea (radius, degrees) {
return Math.pow(radius, 2) * degreeToRadian(degrees) / 2
}

export {
circularArcLength,
circularArcArea
}
19 changes: 19 additions & 0 deletions Maths/test/CircularArc.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { circularArcLength, circularArcArea } from '../CircularArc'

describe('circularArcLength', () => {
it('with natural number', () => {
const arcLengthOfOneThirty = circularArcLength(1, 30)
const arcLengthOfThreeSixty = circularArcLength(3, 60)
expect(arcLengthOfOneThirty).toBe(0.5235987755982988)
expect(arcLengthOfThreeSixty).toBe(3.141592653589793)
})
})

describe('circularArcArea', () => {
it('with natural number', () => {
const arcAreaOfOneThirty = circularArcArea(1, 30)
const arcAreaOfThreeSixty = circularArcArea(3, 60)
expect(arcAreaOfOneThirty).toBe(0.2617993877991494)
expect(arcAreaOfThreeSixty).toBe(4.71238898038469)
})
})

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