Created
March 22, 2021 11:18
-
-
Save vikaskanani/01be2b24055bfb488c501403cdf4eb61 to your computer and use it in GitHub Desktop.
Find area of two intersecting circles
This file contains 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
//reference https://en.wikipedia.org/wiki/Lens_(geometry) | |
function findDelta (d, r, R) { | |
return (1 / 4) * Math.sqrt((-d + r + R) * (d - r + R) * (d + r - R) * (d + r + R) ); | |
} | |
function area (d, r, R) { | |
const delta = findDelta(d, r, R); | |
const cosLeft = (Math.acos(((d * d) + (r * r) - (R * R)) / (2 * d * r))); | |
const cosRight = (Math.acos(((d * d) - (r * r) + (R * R)) / (2 * d * R))); | |
return (r * r) * (cosLeft) + (R * R) * cosRight - 2 * delta; | |
} | |
area(10,10,10); | |
area(1,10,10); | |
area(90,100,10); | |
area(20,10,10); | |
area(19,10,10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment