PDA

View Full Version : convert data points to graph coordinates



jacksmash
01-06-2010, 11:08 AM
This should be simple... but I'm having a hard time coming up with an equation that works every time.

Let's say I have a point, p=(91,1), and I need to plot it on my 2d graph, which, in OpenGL has the x-axis: (1,8) -> (9,8), and the y-axis: (1,8) -> (1,1), because y increases in the downward direction.

So, how do I convert the point 'p' so that is shows at the right place on the graph?

Cheers.

jacksmash
01-06-2010, 11:43 AM
I should add that the point p=(91,1) is actual data. So, I do know the max x and max y values as well.

def
01-06-2010, 02:47 PM
1:1 scale
---------
graph_x = 1+x
graph_y = 8-y

scaled
------
graph_x = 1+(x/max_x*8)
graph_y = 8-(y/max_y*7)

But that is surely not what you are looking for? You need to be more elaborate.