Skip to content

Commit 0121c89

Browse files
authored
Add surface area of torus algorithm
1 parent 08d8c6b commit 0121c89

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Maths/SurfaceAreaOfTorus.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Surface Area of a Torus
3+
* Reference: https://en.wikipedia.org/wiki/Torus
4+
*
5+
* Formula:
6+
* A = 4 * π² * R * r
7+
*
8+
* @param {number} majorRadius - Distance from the center of the tube to the center of the torus (R)
9+
* @param {number} minorRadius - Radius of the tube (r)
10+
* @returns {number} Surface area of the torus
11+
*/
12+
export function surfaceAreaOfTorus(majorRadius, minorRadius) {
13+
if (majorRadius < 0 || minorRadius < 0) {
14+
throw new Error("Radii must be non-negative");
15+
}
16+
17+
return 4 * Math.PI ** 2 * majorRadius * minorRadius;
18+
}

0 commit comments

Comments
 (0)