Jump to content

Cordinate Conversion Script?


Recommended Posts

I am looking for a way to convert the relative coordinates on a 1920 x 1080 resolution to the equivalent coordinates in 800 x 600.

This formula works to do it manually however its extremely inefficient if you are looking to convert a large number of cordiantes: (new_x = old_x * (new_screen_width / old_screen_width)), (new_y = old_y * (new_screen_width / old_screen_width)).

Is there a good Autoit script to do this? Or maybe with another utility?

Link to post
Share on other sites

Welcome to AutoIt and the forum!

You have the formula, that's half the AutoIt script. Screen width and height can be retrieved using the macros @DesktopHeight and @DesktopWidth.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Wow that was a fast reply! Thank you for the warm welcome... Much appreciated.

Would something like this work?

;convert coords (x,y) from (a,b ) screen resolution to (c,d) screen resolution

Func_ConvertCoords( $x, $y, $a, $b, $c = @DesktopWidth, $d = @DesktopHeight )

Local $ret[2] = [( $c * $x ) / $a, ( $d * $y ) / $b]

Return $ret

EndFunc

How to I get Autoit to allow a way to input these cords and then provide an output for it? Please forgive the ignorance as I a complete AutoIt newbie.

Link to post
Share on other sites

I created this test script and it returns some good looking results (didn't check the math).

#include <array.au3>
Global $aResult = _ConvertCoords(100, 200, 800, 600)
_Arraydisplay($aResult)

Func _ConvertCoords($x, $y, $a, $b, $c = @DesktopWidth, $d = @DesktopHeight)
Local $ret[2] = [($c * $x) / $a, ($d * $y) / $b]
Return $ret
EndFunc ;==>_ConvertCoords

To answer your second questions it would help to know why you want to process these coords?

Where are the coords stored now (a file, a database ...)?

What application do you want to feed the new coords to?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
  • 2 weeks later...

I simply want to make a utility (Pixel Conversion Calculator?) that will allow you to convert pixel coordinates between resolutions. It does not seem anything like this exists. You totally put me in the right direction: Thank you!

Here is the code I have been using:

#include <array.au3>

Global $aResult = _ConvertCoords(1920, 1080, 800, 600)

_Arraydisplay($aResult)

Func _ConvertCoords($a, $b, $c, $d, $x = 960, $y = 540)

Local $ret[2] = [($x * ($c / $a)), ($y * ($d / $B))]

Return $ret

EndFunc ;==>_ConvertCoords

This converts the pixel coordinates given in $x and $y. From resolution a, b (in this case 1920 by 1080) to the desired resolution pixel coordinates (in this case 800 x 600).

Example: [($x * ($c / $a)), ($y * ($d / $B))]

is 960 (1920/800), 540(1080/600) = 960(.4166), 540(.4166) = 400, 300

1. Ideally the array would allow you to input the values for $x and $y so it could be a stand alone utility.

2. Even better If you could also change the values for $a,$b,$c,$d then you would also be able to modify the resolution on the fly as well.

Edited by ithelast
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...