@@ -18,6 +18,74 @@ class Geometry {
18
18
static circleCircumference ( radius ) {
19
19
return 2 * Math . PI * radius ;
20
20
}
21
+
22
+ // Method to calculate the area of a triangle given base and height
23
+ static triangleArea ( base , height ) {
24
+ return ( base * height ) / 2 ;
25
+ }
26
+
27
+ // Method to calculate the volume of a sphere given its radius
28
+ static sphereVolume ( radius ) {
29
+ return ( 4 / 3 ) * Math . PI * Math . pow ( radius , 3 ) ;
30
+ }
31
+
32
+ // Method to calculate the area of an equilateral triangle given its side length
33
+ static equilateralTriangleArea ( side ) {
34
+ return ( Math . sqrt ( 3 ) / 4 ) * Math . pow ( side , 2 ) ;
35
+ }
36
+ //Method to calulate the area of the triangle given its side lengths
37
+ static triangleArea_sides ( side1 , side2 , side3 ) {
38
+ const s = ( side1 + side2 + side3 ) / 2 ;
39
+ return Math . sqrt ( s * ( s - side1 ) * ( s - side2 ) * ( s - side3 ) ) ;
40
+ }
41
+ //Method to calulate the area of a square given its side length
42
+ static squareArea ( side ) {
43
+ return Math . pow ( side , 2 ) ;
44
+ }
45
+ //Method to calculate the perimeter of a square given its side length
46
+ static squarePerimeter ( side ) {
47
+ return 4 * side ;
48
+ }
49
+
50
+ // Method to calculate the volume of a cube given its side length
51
+ static cubeVolume ( side ) {
52
+ return Math . pow ( side , 3 ) ;
53
+ }
54
+
55
+ // Method to calculate the volume of a rectangular prism given length, width, and height
56
+ static rectangularPrismVolume ( length , width , height ) {
57
+ return length * width * height ;
58
+ }
59
+
60
+ // Method to calculate the surface area of a rectangular prism given length, width, and height
61
+ static rectangularPrismSurfaceArea ( length , width , height ) {
62
+ return 2 * ( length * width + width * height + height * length ) ;
63
+ }
64
+
65
+ // Method to calculate the volume of a cylinder given its radius and height
66
+ static cylinderVolume ( radius , height ) {
67
+ return Math . PI * Math . pow ( radius , 2 ) * height ;
68
+ }
69
+
70
+ // Method to calculate the surface area of a cylinder given its radius and height
71
+ static cylinderSurfaceArea ( radius , height ) {
72
+ const baseArea = Math . PI * Math . pow ( radius , 2 ) ;
73
+ const lateralArea = 2 * Math . PI * radius * height ;
74
+ return 2 * baseArea + lateralArea ;
75
+ }
76
+
77
+ // Method to calculate the volume of a cone given its radius and height
78
+ static coneVolume ( radius , height ) {
79
+ return ( 1 / 3 ) * Math . PI * Math . pow ( radius , 2 ) * height ;
80
+ }
81
+
82
+ // Method to calculate the surface area of a cone given its radius and height
83
+ static coneSurfaceArea ( radius , height ) {
84
+ const slantHeight = Math . sqrt ( Math . pow ( radius , 2 ) + Math . pow ( height , 2 ) ) ;
85
+ const baseArea = Math . PI * Math . pow ( radius , 2 ) ;
86
+ const lateralArea = Math . PI * radius * slantHeight ;
87
+ return baseArea + lateralArea ;
88
+ }
21
89
}
22
90
23
91
module . exports = Geometry ;
0 commit comments