Saturday, February 11, 2006

Position

It's easy to represent a one-dimensional space on a computer screen: Simply begin at the beginning and show the cells in the space one at a time, left to right.
It can be a bit trickier for a beginner to represent a two-dimensional space. The usual convention is to represent a position with a pair of numbers, each one called a coordinate. The starting point, the origin, is usually given the coordinates (0,0). In mathematics, the convention is that the first number, X, gives the distance going horizontally from left to right, while the second number, Y, gives the distance going from bottom to top.
The way arrays are represented in computers and on the screen are different.
In this case, the first number usually represents the row, and the second, the column, and numbering increases from top to bottom.

However, it's easy to interconvert these representations.
Calling your space coordinates (X, Y), and the corresponding screen coordinates, SCR_X and SCR_Y, the proper equations are:

SCR_X = Y;
SCR_Y = X_MAX - X;

This is a special case of what is called a coordinate transformation.

For beginning and simple cases, without going into graphics programming, it's possible to go back to the origins of computer graphics and use text characterers to represent the cells of a small space.

A simple routine to display a simple space wmight then be:

for (scr_x = 0; scr_x <= X_MAX; 1)
{
y = scr_x;
for (scr_y = 0; scr_y <= Y_MAX; 1)
{
x = X_MAX - scr_y;
display_cell (x, y);
}
begin new line;
}

But so far, I have only talked about space and time. I haven't talked about either the properties or contents of space.

0 Comments:

Post a Comment

<< Home