Hit Enter or
TAGS:  unity3d (9)  art (6)  experience (4)  hci (4)  virtual reality (4)  vr (4)  ar (3)  computer-human-interaction (3)  digital-art (3)  generative (3)  installation (3)  interactive (3)  augmented reality (2)  business-activation (2)  graphics (2)  math (2)  p5js (2)  research (2)  shaders (2)  tangible-interfaces (2)  tutorial (2)  algorithm (1)  app (1)  architecture (1)  arduino (1)  c# (1)  c#" (1)  design (1)  development (1)  engineering (1)  git (1)  iot (1)  maths (1)  mesh (1)  nft (1)  programming (1)  sdk (1)  serial (1)  snapchat (1)  tools (1)  visualization (1)  work (1) 

Compute width and height from diagonal and aspect ratio

Table Of Contents


Problem

When the information about a screen, a window or a generic rectangle is limited to its diagonal and an the aspect ratio (the width divided by the height) and we need to know width and height, we have a little problem. It must be easy right? Well.. not as obvious as most people expect (how many of your friends know the right answer?) but still the solution isn’t difficult and it’s a nice example of use of some known quadratic formulas.

If you are here just for the formulas jump to Summary

Requirements

You need to be confident with:

  • The Pitagoras’ theorem : d² = a² + b²
  • Square of a binomial : (a + b)² = a² + b² + 2ab

Definitions

d : length of the diagonal
w : width
h : height
r : ratio (w/h)

Solution

Since we are always dealing with a right angle, from Pitagoras’ theorem we know that the square of the diagonal equals the sum of the square of the sides:

1. d² = w² + h²

We also know that by using the definition of aspect ratio, which is w/h, if we have one of the two lengths (w or h) we can easily compute the other. So if w is known then

2. h = w / r

and if h is known then

3. w = h * r

Find w

From the equation 1. let’s find w. First of all, we can use 2. to express h in w terms.

4. d² = w² + (w/r)²

Now looking closely at the right hand side of the equation, we find out that it’s very close to the right side of a square of a binomial (a + b)² = a² + b² + 2ab. The only missing part is + 2ab. So, treating w as a and w / r as b, let’s add the missing term to both sides:

5. d² + 2w(w/r) = w² + (w/r)² + 2w(w/r)

Gathering the right hand side into a squared binomial, we obtain

6. d² + 2w(w/r) = (w + w/r)²

Elaborating a bit

7. d² + 2(w²)/r = (w + w/r)²
8. d² + 2(w²)/r = (w (1 + 1/r))²
9. d² + 2(w²)/r = w² (1 + 1/r)²

To understand 9. you might have to remember that extracting a value from a square, it has to be squared itself, thus why we have w² (1+1/r)².

10. d² = w² (1 + 1/r)² - 2(w²)/r

Gather up the :

11. d² = w² [(1 + 1/r)² - 2/r]

We can finally isolate w:

12. w² = d² / [(1 + 1/r)² - 2/r]
13. w = SQRT( d² / [(1 + 1/r)² - 2/r] )

And that’s our width.

Of course once we have the width we can quickly obtain the height from the equation 2.

But let’s quickly see the same procedure for the height:

Find h

d² = (hr)² + h²
d² = (hr + h)² – 2hhr
d² = (hr + h)² – 2h²r
d² = h²(r + 1)² – 2h²r
d² = h² [(r + 1)² – 2r]
h² = d² / [(r + 1)² – 2r]
h = SQRT(d² / [(r + 1)² – 2r])

Case Study

Your neighbour calls you and shows you his new TV, proudly measures its width and mixing laughs and words, tells you it’s 65 inches wide and that it’s way bigger than your 65 inches tv. It just so happens that you were considering buying a peculiar 4K 75 inches TV with a 16:10 aspect ratio. Will it be wider than your neighbour’s TV which is 65 inches wide?

w = SQRT( 75² / ((1 + 1/(16:10))² - 2/(16:10)) )
w = SQRT( 5625 / ((1 + 1/1.6)² - 2/(1.6)) )
w = SQRT( 5625 / ((1.625)² - 1.25) )
w = SQRT( 5625 / (2.64 - 1.25) )
w = SQRT( 5625 / 1.39 )
w = SQRT( 4046.76 )
w = 63.61

So no, your neighbour still has a bigger TV. It’s a good occasion to ask yourself whether you really need a bigger TV. And whether it’s time to befriend a better neighbour.

Test

h = w/r = 63.61 / 1.6 = 39.75
d = SQRT(w² + h²) = SQRT(63.61² + 39.75²) = SQRT(5626.3) = 75

Summary

Given a diagonal d and an aspect ratio r we can calculate width w and height h with the following formulas:

w = SQRT( d² / [(1 + 1/r)² - 2/r] )
h = SQRT( d² / [(r + 1)² – 2r] )

Once w or h is known, the other can be easily calculated with one of the two formulas:

w = h*r
h = w/r