높이 = 너비 × tan(각도). 아래 코드는 빗변(c)을 거쳐 돌아가지만 결과는 100 * Math.tan(angle * Math.PI / 180) 과 같다 — Math.tan 은 라디안을 받으니 도(°)를 바꿔 넣는다.1

function getTiltedHeight(angle) {
  const a = 100;
  const A = 90 - angle;
  
  const c = a / Math.sin(Math.PI * A / 180);
  const b = Math.sqrt(Math.pow(c, 2) - Math.pow(a, 2));
  
  return `${Math.abs(b)}%`;
}

Footnotes

  1. Math.tan() - MDN: “The Math.tan() static method returns the tangent of a number in radians.” ↩

`#122`