How do I map pixels to a coordinate system?

7.5k Views Asked by At

As often happens I'm not sure of the name of what I'm trying to do, so I'm having difficulty searching it. I know this is basic algebra, but my math is null so I'm struggling with it greatly.

I have a coordinate system that starts from 0,0 in the bottom left corner, and ends in 1,1 in the top right corner. I must "translate" from coordinates to pixels and viceversa. I'm including a diagram to clarify what I'm trying to do.

I'm trying to do this with Javascript, but I guess it's irrelevant. A formula is enough to get me started.

Thanks!

enter image description here

1

There are 1 best solutions below

3
On BEST ANSWER

Your coordinates look odd, but going from co-ordinates to pixels, you probably want something like $$f(x,y) = (190y+5,195-190x)$$ and going from pixels to coordinates $$g(a,b) = \left(\frac{195-b}{190},\frac{a-5}{190},\right)$$ but you may need to adjust this slightly to deal with what happens on the edges