mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
algorithm class: cone (#1253)
This commit is contained in:
25
Geometry/Cone.js
Normal file
25
Geometry/Cone.js
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* This class represents a circular cone and can calculate its volume and surface area
|
||||
* https://en.wikipedia.org/wiki/Cone
|
||||
* @constructor
|
||||
* @param {number} baseRadius - The radius of the base of the cone.
|
||||
* @param {number} height - The height of the cone
|
||||
*/
|
||||
export default class Cone {
|
||||
constructor (baseRadius, height) {
|
||||
this.baseRadius = baseRadius
|
||||
this.height = height
|
||||
}
|
||||
|
||||
baseArea = () => {
|
||||
return Math.pow(this.baseRadius, 2) * Math.PI
|
||||
}
|
||||
|
||||
volume = () => {
|
||||
return this.baseArea() * this.height * 1 / 3
|
||||
}
|
||||
|
||||
surfaceArea = () => {
|
||||
return this.baseArea() + Math.PI * this.baseRadius * Math.sqrt(Math.pow(this.baseRadius, 2) + Math.pow(this.height, 2))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user