Skip to content

Added surface area calculation for pyramid #5450

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Please read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute

## Algorithms
Our [directory](DIRECTORY.md) has the full list of applications.

THIS IS MY CHANGES.
20 changes: 20 additions & 0 deletions src/main/java/com/thealgorithms/maths/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,24 @@ public static double surfaceAreaCone(final double radius, final double height) {
}
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
}


/**
* Calculate the surface area of a pyramid with a square base.
*
* @param sideLength side length of the square base
* @param slantHeight slant height of the pyramid
* @return surface area of the given pyramid
*/
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
if (sideLength <= 0) {
throw new IllegalArgumentException("Must be a positive sideLength");
}
if (slantHeight <= 0) {
throw new IllegalArgumentException("Must be a positive slantHeight");
}
double baseArea = sideLength * sideLength;
double lateralSurfaceArea = 2 * sideLength * slantHeight;
return baseArea + lateralSurfaceArea;
}
}