简体   繁体   中英

Resoultion and Aspect Ratio

I have a screen that is 1920x1080 and another screen that is 1280x720. These both have a 16:9 aspect ratio.

I have a bot that moves the mouse to a particular set of coordinates on the screen; for example, I can move the mouse to 500x720 on the screen 1920x1080.

What is the equation to have the mouse move to the same coordinates 500x720 proportional to the screen of 1280x720?

Basically you just have to multiply the coordinates by scale factor. Below, sx and sy will be numbers (within the interval 0-1) which transform from the larger screen to the smaller screen coordinates.

If the screens are the same aspect ratio, then sx == sy , but this need not be true in the general case.

>>> w1, h1 = 1920., 1080.
>>> w2, h2 = 1280.,  720.
>>> sx, sy = w2/w1, h2/h1  # scale factors in horizontal and vertical dimensions
>>> x1, y1 =  500.,  720.
>>> x2, y2 = sx*x1, sy*y1
>>> x2, y2
(333.3333333333333, 480.0)

By the way, to transform back the other direction the scale factors would be 1/sx and 1/sy .

mxn on a 1920x1080 screen
is m*(1280/1920) xn*(720/1080) on a 1280x720 screen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM