DEV Community

PackForge Industries
PackForge Industries

Posted on

Will It Fit? Turn a Laptop's Screen Size into Real Dimensions with Python

"Fits 15.6-inch laptops" is printed on a lot of backpacks, but 15.6 inches is the screen diagonal, not the size of the machine. A bit of Pythagoras turns the diagonal into width and height.

Screen size from diagonal and aspect ratio

For a ratio of w:h, the diagonal is the hypotenuse, so each side is a share of it:

from math import hypot

def screen_mm(diag_in, ratio=(16, 9)):
    rw, rh = ratio
    k = diag_in * 25.4 / hypot(rw, rh)
    return round(rw * k), round(rh * k)

for d, r in [(14, (16, 9)), (15.6, (16, 9)), (16, (16, 10)), (17.3, (16, 9))]:
    print(d, r, screen_mm(d, r))
Enter fullscreen mode Exit fullscreen mode
14 (16, 9) (310, 174)
15.6 (16, 9) (345, 194)
16 (16, 10) (345, 215)
17.3 (16, 9) (383, 215)
Enter fullscreen mode Exit fullscreen mode

Notice that a 16-inch 16:10 screen is as wide as a 15.6-inch 16:9 one, just taller.

From screen to body

The body adds bezels, plus a deeper bottom edge for the hinge. The allowances below are rough guesses, so replace them with your laptop's spec sheet when you have it:

def body_estimate(diag_in, ratio=(16, 9), side=12, top=12, bottom=40):
    w, h = screen_mm(diag_in, ratio)
    return w + 2 * side, h + top + bottom

print(body_estimate(15.6))  # (369, 246)
Enter fullscreen mode Exit fullscreen mode

Checking a sleeve

def fits(laptop_mm, sleeve_mm, margin=10):
    return all(s >= l + margin for l, s in zip(laptop_mm, sleeve_mm))
Enter fullscreen mode Exit fullscreen mode

Measure the sleeve inside, flat, and allow a few millimetres for the padding.

PackForge's bulk laptop backpacks (about 20 to 30 litres) have a padded compartment for 15.6-inch laptops, with 17-inch versions made to order and logo branding available: Laptop backpacks.

Top comments (0)