Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
    
bottom left pixels should read "5, 195", sorry. –  Duopixel Feb 16 '11 at 22:44
    
should it read 1,0 in the bottom right or top left? (instead of 0,1, which appears twice) –  Henry Feb 16 '11 at 22:51
    
Ugh, true, uploaded fixed image. –  Duopixel Feb 16 '11 at 22:55
    
An interesting related issue for you may what pixels correspond to the points on a particular straight line. One approach to this is known as Bresenham's Algorithm: en.wikipedia.org/wiki/Bresenham%27s_line_algorithm –  Joseph Malkevitch Feb 16 '11 at 23:32
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks! But the y axis is inverted, how do I account for that? –  Duopixel Feb 16 '11 at 22:59
    
I have edited my reply –  Henry Feb 16 '11 at 23:01
    
Thanks! I've implemented it and it's working perfectly. –  Duopixel Feb 16 '11 at 23:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.