# 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?

##### 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### 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.

##### 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### Share on other sites

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 / \$)]

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 / \$)]

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...