-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49dd1eb
Add an algorithm to find length and area of an arc of a circle
prashalruchiranga 0de33fa
Updated to follow Javascript Standard Style
prashalruchiranga 59663e9
Update CircularArc.js
prashalruchiranga 2be2bce
Update CircularArc.js
prashalruchiranga 83259b3
Add tests
prashalruchiranga d50e160
Followed Javascript standard style
prashalruchiranga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.