Sign in to follow this  
Followers 0
ithelast

Cordinate Conversion Script?

5 posts in this topic

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 this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


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
Sign in to follow this  
Followers 0