I wanted to essentially compute the scaling factor of 2 numbers, based on two other numbers (I am unable to describe it well).
Eg:
Lets say I have an image of size 200x300 (aspect is 2:3) and I need to find a ratio that is that is closest to another ratio, lets say 4:5.
Now normally I would just multiply to find the ratio keeping one of the numbers common, so in this case the ratio would become 4:6 (multiplying 2 and 3 with 2).
But I would like a method that would give me numbers with the ratio 2 : 3, but closer to 4 and 5, for eg., if I would have multiplied by 1.9 then the ratio would be 3.8 : 5.7, whose total difference from the previous ratio would be less than that of 4 : 6 (My heuristic for total difference is |(4-x)|+|(5-y)|, which in the case of 4 : 6 => 1, and with 3.8 : 5.7 => 0.9)
In essence, I need some kind of method to find those numbers which give that minimum gap. If someone has a better heuristic as well I would also be interested in that
PS:This will need to be implemented in Javascript, so if you have some code I could use I would greatly appreciate it, obviously this would be extra and totally not expected.
Thank you