Reputation: 31
I have some screen coordinates with a maximum Width of 650; so 0 - 650. If i have some arbitrary scale say from 40 to 50, where 40 is the lowest point and 50 being the maximum. How do I convert say a screen coordinate of 430 relative to the scale?
Upvotes: 0
Views: 421
Reputation: 25013
It's just maths:
static double ScreenToScaled(int screenMin, int screenMax, int scaledMin, int scaledMax, int screenValue)
{
return (double)(screenValue - screenMin) / (double)(screenMax - screenMin) * (scaledMax - scaledMin) + scaledMin;
}
To see how it works, you can draw a chart of the screen value compared to the scaled value:
(Apologies for the crudeness of the chart.)
With your values of the screen and scaled values, your conversion ends up as y = 0.01538 x + 40 where x is the screen value and y is the scaled value.
Upvotes: 0
Reputation: 2906
any other condition? based on what you gave us, it is just a linear mapping, which maps zero to 40 and 650 to 50.
with this in mind, each unit in new coordinate is equal to 65 in old one. Then 430/65=6.61, which means 430 is mapped to 40+6.61=46.61
Upvotes: 1