math-base-geometry
Version:
utils for math geometry
46 lines (33 loc) • 1.05 kB
JavaScript
const utils = require("../utils");
const handleDecimal = utils.handleDecimal;
const PI = utils.PI;
const isNumber = utils.isNumber;
function radius(volume, height, decimalLimit) {
if (!isNumber(volume) || !isNumber(height)) {
throw "volume and height should be numbers";
}
const formula = Math.sqrt(volume / (PI * height));
const resp = handleDecimal(formula, decimalLimit);
return resp;
}
function height(volume, radius, decimalLimit) {
if (!isNumber(volume) || !isNumber(radius)) {
throw "volume and radius should be numbers";
}
const formula = volume * (PI * radius * radius);
const resp = handleDecimal(formula, decimalLimit);
return resp;
}
function volume(radius, height, decimalLimit) {
if (!isNumber(volume) || !isNumber(radius)) {
throw "volume and radius should be numbers";
}
const formula = PI * radius * radius * height;
const resp = handleDecimal(formula, decimalLimit);
return resp;
}
module.exports = {
radius,
height,
volume
}