# Fit screen resolution given ratio and total number of pixels

Given:

width: 1920
height: 1080
total pixels: width * height = 2073600
aspect ratio: 1920 / 1080 ~= 1.8


How do I calculate a new resolution (width and height) with the same aspect ratio but a new pixel count? In the other words one that satisifes the following conditions:

width * height = 10000
width / height = 1.8


There are infintely many solutions to that equation system however and I want the solution that most resembles a screen resolution. I suppose that means the solution with the minimum distance abs(widht - height), but I'm not really sure.

-
You mean W/H = 1.8 and W*H = 10000 then W = 10000/H; 10000/1.8 = $H^2$ and H $\ge 0$, but this gives only one solution – Ram Jan 14 '13 at 5:26

Note that you have two variables, $width$ and $height$, and two equations. There is only one solution.

height = aspect_ratio * width
width / height = aspect_ratio

width * height = total_pixels
aspect_ratio * width² = total_pixels


Solve to $width$ and you have $height$.

-

You have two equations in two unknowns, so there should generally be a unique solution. In your example, you can find width^2=18000, so width is about 134. Then height is about 134/1.8 or about 74. Now the problem is that integer division and square roots are not exact, so you need to specify what you are willing to compromise. 74*134=9916, which is very close to 10000-can you live with that? If not, explore numbers nearby and choose your favorite.

-