Reputation: 1671
I am writing a program that converts the screen mapped pixels to actual resolution. As an example on the screen the co-ordinates are from (0,0) [top left] to (1,1) [bottom right]. My computer monitor has the resolution of 1600x900. So i need a way to map (0,0) to (0X0) and (1,1) to (1600x900) as well as everything in between such as (0.56,0.7) to Whatever it translates to in resolution. Does anyone know a way to do this?
Upvotes: 0
Views: 155
Reputation: 22842
You just need to scale them like this:
To go from actual to co-ordinates:
x = x * actualmax/coordmax
so in your example, using a y-coordinate of 0.333
x = 0.333 * 900/1 = 300
To go from co-ordinates to actual:
x = x * coordmax/actualmax
so in your example, using a y-coordinate of 300
x = 300 * 1/900 = 0.333
Upvotes: 2