Given two rectangles, and a maximum difference score, tell me whether the aspect ratio of these rectangles are considered similar or not?

For example a $2\times4$ rectangle [ratio $0.5$] and a $2\times3$ [ratio $0.66$] are considered similar, meaning that the difference of $0.16$ is still considered similar.

Also a $4\times2$ rectangle [ratio $2$] and a $3\times2$ rectangle [ratio $1.5$] are both considered similar and the difference is $0.5$ which is much larger than $0.16$ and yet is considered similar.

Another example of a $3\times2.9$ rectangle and a $2.8\times3.1$ rectangle are also considered similar.

How can one give one formula for calculating such a thing?

Further clarification

Let us represent a completely identical ratio with a score of $0$, meaning that there is no change between them

Let's represent a completely different ratio with a score of $1$

Let's say that the largest rectangle can be up to $1000$ width or up to $1000$ height

Example of the same ratio: $2\times3$ rectangle and $4\times6$ rectangle and the like

An example of a completely different ratio: a $1\times1000$ rectangle and a $1000\times1$ rectangle


There is no mathematical definition for the similarity of aspect ratios. You might consider the ratio of the aspect ratios as a measure of aspect ratio similarity. The closer to $1$ the more similar.

You could then choose a cutoff point for "similar enough", depending on your application.

| cite | improve this answer | |
  • $\begingroup$ Are you actually saying there is no solution? I could not understand, please explain more. $\endgroup$ – google dev Sep 24 at 5:44
  • $\begingroup$ There is no mathematical definition (I know of) that describes how similar two rectangles with different aspect ratios are. If you need such a measurement in your application you have to invent one. My answer has a suggestion. $\endgroup$ – Ethan Bolker Sep 24 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.