Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created September 17, 2018 09:59
Show Gist options
  • Save acdimalev/4cd6ccd3671cc117fbd745ffb4b6c1b5 to your computer and use it in GitHub Desktop.
Save acdimalev/4cd6ccd3671cc117fbd745ffb4b6c1b5 to your computer and use it in GitHub Desktop.

let w and h be the width and the height of the screen, respectively.

let a be the ratio of the width to the height.

a = w / h

Note that this is equivalent to the aspect ratio of the screen for the case where the screen is wider than it is tall, and the inverse of the aspect ratio otherwise.

Let q be the area of the screen.

q = w * h

In order to retain scaling relative to the area of the screen, let the area of the screen be arbitrarily quantified as a value of 1.

q = 1

Note then, that the width and height of the screen can be described in terms a.

First, note that our equation for a provides an alternate definition for w.

a = w / h
w = a * h

This can, then, be substituted in the definition of q.

q = w * h
q = a * h * h

And then we can solve for h.

q = a * h * h
h * h = q / a
h = sqrt(q / a)
h = sqrt(1 / a)

Similarly, we now have two different options to solve for w.

q = w * h
w = q / h
w = 1 / sqrt(1 / a)

w = a * h
w = a * sqrt(1 / a)

This, of course, requires that the alternate definitions be equivalent.

1 / sqrt(1 / a) = a * sqrt(1 / a)
0 = 1 / sqrt(1 / a) - a * sqrt(1 / a)

If you're feeling lazy, just ask Wolfram Alpha whether or not these are equivalent.

http://www.wolframalpha.com/input/?i=1+%2F+sqrt(1+%2F+x)+-+x+*+sqrt(1+%2F+x)

Otherwise, you can poke, prod, and question this math.

1 / sqrt(1 / a) = a * sqrt(1 / a)
1 = a * sqrt(1 / a) * sqrt(1 / a)
1 = a * 1 / a
1 = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment