DEV Community

Tihmlo
Tihmlo

Posted on Fully Autonomous

Calculate screen width and viewing angle from a display diagonal

A screen diagonal is useful until you need to know whether two displays fit between a wall and a speaker. The conversion depends on aspect ratio. A 34-inch ultrawide can need more horizontal space than a larger 16:9 screen.

Convert the diagonal into active width

Treat the horizontal and vertical ratio as the legs of a right triangle. Divide the diagonal by the length of the ratio's hypotenuse, then multiply by each leg. Here is a small JavaScript function you can run in a browser console or Node.js.

function panelSize(diagonal, ratioWidth, ratioHeight) {
  for (const value of [diagonal, ratioWidth, ratioHeight]) {
    if (!Number.isFinite(value) || value <= 0) {
      throw new RangeError("The diagonal and ratio must be positive finite numbers");
    }
  }
  const scale = diagonal / Math.hypot(ratioWidth, ratioHeight);
  return { width: ratioWidth * scale, height: ratioHeight * scale };
}

const near = (actual, expected) => Math.abs(actual - expected) < 0.02;
console.assert(near(panelSize(27, 16, 9).width, 23.53));
console.assert(near(panelSize(34, 21, 9).width, 31.25));
console.assert(near(panelSize(32, 16, 9).width, 27.89));
Enter fullscreen mode Exit fullscreen mode

The 34-inch example occupies about 3.36 inches more horizontally than the 32-inch example, even before bezels and clearance. A marketed ultrawide ratio may be rounded. Use the panel's stated physical dimensions when a fit is close.

Compare the angle at your seat

For a flat screen facing you, measure from your eyes to the center of the panel. With width and distance in the same unit, the horizontal viewing angle is:

function horizontalAngle(width, distance) {
  if (![width, distance].every(value => Number.isFinite(value) && value > 0)) {
    throw new RangeError("Width and distance must be positive finite numbers");
  }
  return 2 * Math.atan2(width / 2, distance) * 180 / Math.PI;
}

const panel = panelSize(27, 16, 9);
console.assert(near(horizontalAngle(panel.width, 24), 52.23));
console.assert(near(horizontalAngle(panel.width, 30), 42.83));
Enter fullscreen mode Exit fullscreen mode

A stand can change the actual distance, and moving the panel back changes the angle without freeing any horizontal desk space. These figures describe geometry. Check the manufacturer's chassis and stand dimensions separately, and use the actual mounting position if a bracket changes the depth.

The screen dimensions and viewing geometry worksheet lets you compare alternate sizes and distances using the same basic inputs. I help maintain TIHMLO. This post was prepared with AI assistance.

Top comments (0)