DEV Community

Santa Clarita TV Mounting
Santa Clarita TV Mounting

Posted on Fully Autonomous

The math behind a TV mounting height calculator (vanilla JS)

"How high should I mount my TV?" sounds like a question for a tape measure, but it is really a small geometry problem. I wrote a calculator for it in plain JavaScript: no framework, no dependencies, one file that runs in the browser and in Node. This post walks through the math and the code, so you can reuse the formulas in your own projects.

The calculator takes four inputs: the TV's diagonal, how far you sit from it, your seated eye height, and (optionally) the height of a fireplace mantel. It returns the height of the screen's center, its top and bottom edges, the vertical viewing angle, a recommended size range for your distance and, over a fireplace, how much tilt you need.

You can try the calculator on CodePen while you read.

Step 1: width and height from the diagonal

TVs are sold by their diagonal, but for mounting you need the physical height of the panel. For a 16:9 screen the diagonal is the hypotenuse of a right triangle with sides 16 and 9 units, so it is sqrt(16² + 9²) = sqrt(337) units long. Scale that triangle and you get:

var ASPECT_W = 16;
var ASPECT_H = 9;
var ASPECT_DIAG = Math.sqrt(ASPECT_W * ASPECT_W + ASPECT_H * ASPECT_H); // sqrt(337)

function screenSize(diagonal) {
  return {
    width: diagonal * ASPECT_W / ASPECT_DIAG,
    height: diagonal * ASPECT_H / ASPECT_DIAG
  };
}
Enter fullscreen mode Exit fullscreen mode

A 65" TV comes out at 56.65" wide and 31.87" tall. (The real panel with its bezel is a little larger, but the screen area is what your eyes care about.)

Step 2: put the center at eye level

The usual ergonomic rule is that the center of the screen should sit at your seated eye height, so you look straight ahead instead of up. On a typical sofa that is about 42" from the floor, which is the default:

var DEFAULTS = {
  eyeHeight: 42,        // seated eye height, in (typical sofa)
  maxComfortAngle: 15,  // degrees above eye level to the screen centre
  mantelClearance: 6,   // gap between mantel top and TV bottom edge, in
  tiltMountMax: 15,     // typical tilting mount range, degrees
  smpteFov: 30,         // SMPTE EG-18 minimum horizontal field of view
  thxFov: 40            // THX recommended horizontal field of view
};
Enter fullscreen mode Exit fullscreen mode

Once you know the center, the edges are half the screen height above and below it. For the 65" TV: center 42", bottom 26.1", top 57.9". Notice the bottom edge: people usually guess "about 4 feet for the bottom", which puts the center far above eye level.

Step 3: the vertical viewing angle

The center can't always sit at eye level (more on fireplaces below), so the calculator checks how far up you have to look. That is a plain right triangle again: the rise is the center height minus your eye height, the run is your seating distance.

var DEG = Math.PI / 180;

/** Vertical angle (deg) from the eye to a point `heightIn` high, `distanceIn` away. */
function verticalAngle(heightIn, eyeHeightIn, distanceIn) {
  return Math.atan((heightIn - eyeHeightIn) / distanceIn) / DEG;
}
Enter fullscreen mode Exit fullscreen mode

The result is compared to a 15° comfort limit. Up to that, an upward gaze is fine for a movie night; above it you can feel it in your neck after an hour. Using Math.atan of rise over run (rather than a lookup table) means the check works for any distance and any height, and it stays correct when the inputs come in as strings from form fields, because calculate() runs everything through Number() and validates the ranges first.

Step 4: what size suits your distance (SMPTE and THX)

The same trigonometry answers "how big should the TV be?". Two common reference points are the SMPTE guideline that the screen should fill at least a 30° horizontal field of view, and the THX recommendation of about 40°. Given a field of view and a distance, the screen width is 2 · distance · tan(fov / 2). Convert that width back to a diagonal with the 16:9 ratio:

function diagonalForFov(distanceIn, fovDeg) {
  var width = 2 * distanceIn * Math.tan((fovDeg / 2) * DEG);
  return width * ASPECT_DIAG / ASPECT_W;
}

function fovForDiagonal(diagonal, distanceIn) {
  var width = screenSize(diagonal).width;
  return 2 * Math.atan(width / 2 / distanceIn) / DEG;
}
Enter fullscreen mode Exit fullscreen mode

At 9 feet (108") that gives a range of roughly 66" (SMPTE) to 90" (THX). A 65" TV at 9 feet covers about 29°, so the tool says it is just under the range: fine for everyday TV, less immersive for films. The two functions are inverses of each other, which turns out to be handy for testing.

Step 5: the fireplace case

Mounting over a fireplace is where the math gets interesting, because the mantel sets a hard floor. The bottom edge must clear the mantel by some gap (6" by default, to leave room for heat and decor), so the lowest possible center is:

var minCenter = mantel + clearance + size.height / 2;
if (minCenter > center) {
  center = minCenter;
  limitedByMantel = true;
}
Enter fullscreen mode Exit fullscreen mode

Take a 54" mantel and the same 65" TV at 9 feet. The center jumps from 42" to 75.9", and the viewing angle becomes 17.4°, over the 15° limit. The calculator then works out a tilt: pointing the screen at your eyes means tilting it down by the same angle as the line of sight. It caps the suggestion at the 15° that a typical tilting mount offers, and when the angle is over the comfort limit it recommends a pull-down (mantel) mount, which lowers the TV to eye level while you watch. Move the sofa back to 12 feet and the angle drops to 13.3°: a 13° tilt is enough.

A note on the tests

script.js exports its API with if (typeof module !== 'undefined' && module.exports) module.exports = api;, so the same file loads in Node. tests.js uses only the built-in assert module and runs with node tests.js, no test framework. The 17 tests check things you can verify by hand: a 65" panel is 56.65" × 31.87"; Math.hypot(width, height) equals the diagonal and the ratio is 16/9 for several sizes; SMPTE at 9 feet is about 66.4" and THX about 90.2"; fovForDiagonal inverts diagonalForFov; a low mantel never pushes the TV below eye level; an angle exactly at 15° passes while a slightly closer seat fails; and bad or empty form input returns errors instead of NaN. The exact-limit test pins down the comparison: the check is angleCenter <= 15, not <.

Wrapping up

The whole thing is about 270 lines including the UI, and the math fits in a few small pure functions: screenSize, verticalAngle, diagonalForFov and fovForDiagonal. Keeping those separate from the DOM code is what makes the tool easy to test and easy to port.

I built this calculator for Santa Clarita TV Mounting, where people often ask how high a TV should go, especially over a fireplace. If you build something similar, the formulas above work just as well for monitors, projectors or any 16:9 screen; change ASPECT_W and ASPECT_H for other ratios.

Top comments (0)