Page 1 of 1

Ratio of any Two Numbers

PostPosted: Sat Jun 25, 2016 4:37 am
by ajhunt
Hi All, does anyone know of a way to find the ratio of two different numbers in an function please. As an example we all know 400x300 = 4:3, and 1600x900 = 16:9 (simply remove the 00's) but what about numbers like 1050x700 (which actually is 3:2 I believe). On paper can do it by finding common number but seeking a function or formular can use to see after a user types in their number it shows what ratio they are to each other. Any help appreciated. Many thyanks.

Re: Ratio of any Two Numbers

PostPosted: Sat Jun 25, 2016 4:59 am
by Gaev
ajhunt:

If you permit users to enter any two values (width, height), you can end up with ratios that are weird e.g. 745,701 could very well end up with a ratio of 745:701

You might be better off providing users with a dropdown/listbox of the most common screen resolutions ... and have them choose one that matches (or is the closest to) one of the choices.

This page ... http://www.w3schools.com/browsers/browsers_display.asp ... provides the ones used by 97% of this website's users.

This page ... https://en.wikipedia.org/wiki/Display_resolution ... provides screen pixels (and corresponding aspect ratios) for the common screen standards.

And another one here ... http://www.rapidtables.com/web/dev/scre ... istics.htm

Re: Ratio of any Two Numbers

PostPosted: Sat Jun 25, 2016 8:00 am
by ajhunt
Hi Gaev, that's my point as they can enter any numbers. They are resolutions of webcams and dlsr camera not screen resolutions and wanted to know what ratio they have chosen to capture their images at. With so many different cameras it makes it difficult to do a dropdown list. Thanks for your reply as always.

Re: Ratio of any Two Numbers

PostPosted: Sat Jun 25, 2016 8:34 am
by Gaev
ajhunt:

They are resolutions of webcams and dlsr camera not screen resolutions and wanted to know what ratio they have chosen to capture their images at. With so many different cameras it makes it difficult to do a dropdown list.


I am not familiar with aspect ratios deployed by webcams or dslr cameras.

But let us address this from another angle i.e. why exactly do you need the aspect ratio ? ... are you trying to map the output from such devices to a "rectangle on your screen" so that the result "does not appear skewed" ? ... if so, it would be a simple math formula ... given the width and height of the input stream ... and the "maximum available" width & height for output.

Re: Ratio of any Two Numbers

PostPosted: Mon Jun 27, 2016 2:27 am
by Peter
ajhunt wrote:my point as they can enter any numbers.


Hi, ajhunt!

Try out this example, may be it's useful for you.

Regards,
Peter

Re: Ratio of any Two Numbers

PostPosted: Mon Jun 27, 2016 7:16 am
by ajhunt
Hi Peter, many many thanks - it will work it perfectly. Gratefully received. :):):)