Skip to content
Closed
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
18 changes: 18 additions & 0 deletions Maths/SurfaceAreaOfTorus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Surface Area of a Torus
* Reference: https://en.wikipedia.org/wiki/Torus
*
* Formula:
* A = 4 * π² * R * r
*
* @param {number} majorRadius - Distance from the center of the tube to the center of the torus (R)
* @param {number} minorRadius - Radius of the tube (r)
* @returns {number} Surface area of the torus
*/
export function surfaceAreaOfTorus(majorRadius, minorRadius) {
if (majorRadius < 0 || minorRadius < 0) {
throw new Error("Radii must be non-negative");
}

return 4 * Math.PI ** 2 * majorRadius * minorRadius;
}
Loading