Published
Edited
Jun 24, 2020
Importers
3 stars
Insert cell
Insert cell
// Returns the length of the longest side (hypotenuse) of a right-angled triangle,
// based on the length of the other two sides
function triangleHypotenuse(sideA, sideB) {
return Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2));
}
Insert cell
//returns the height of an equilateral triangle based on the width of the base
function equilateralHeight(width) {
return Math.sqrt(width * width - ((width / 2) * width) / 2);
}
Insert cell
function angleTan(opposite, adjacent) {
return Math.atan(opposite / adjacent);
}
Insert cell
//returns the length of the opposite side to the angle, using the hypotenuse's length
function oppositeSin(angle, hypotenuse) {
return Math.sin(angle) * hypotenuse;
}
Insert cell
//returns the length of the adjacent side to the angle, using the hypotenuse's length
function adjacentCos(angle, hypotenuse) {
return Math.cos(angle) * hypotenuse;
}
Insert cell
//returns the length of the opposite side to the angle, using the adjacent side's length
function oppositeTan(angle, adjacent) {
return Math.tan(angle) * adjacent;
}
Insert cell
//returns the length of the adjacent side to the angle, using the opposite's length
function adjacentTan(angle, opposite) {
return opposite / Math.tan(angle);
}
Insert cell
//returns the length of the unknown side of a right angle triangle, using the other two sides' lengths
function triangleSide(sideA, sideB) {
var hypothenuse, shorterSide;
if (sideA > sideB) {
hypothenuse = sideA;
shorterSide = sideB;
} else {
hypothenuse = sideB;
shorterSide = sideA;
}
return Math.sqrt(Math.pow(hypothenuse, 2) - Math.pow(shorterSide, 2));
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more