Computer Science I
MC140.01 / MC140.02
Fall 2000
Hints for Assignment 3
due Wednesday 4 October 2000, 12noon
When working with computer graphics, there are typically
three coordinate systems defined:
- screen coordinates -- these are the coordinates
of the physical computer screen, expressed in pixels.
Typically, your Windows display will have the
dimensions 800 X 600 pixels.
- window coordinates -- these are the coordinates
of the window on the screen in which you will be drawing
graphics. Typically, this is created by defining an origin --
an (x,y) position in screen coordinates for the upper left
corner of the window -- as well as the window's width and
height. All of these are expressed in pixels.
- graphics coordinates -- these are the coordinates
that you do your drawing in. Typically, you define axes
inside your window and draw using those axes just as if you
were plotting on graph paper. You must have some method of
translating between the graphics coordinates and the
window coordinates.
With this assignment, you can think of plotting the shapes
(rectangle, triangle and circle) on a piece of graph paper.
Your grid data structure is that piece of graph paper.
It has dimensions MAX by MAX.
The squares on your grid can be numbered in two ways:
- using window coordinates,
going from 0 to MAX
- using graphics coordinates,
going from -(MAX-1)/2 to +(MAX-1)/2
You can translate between the two coordinate systems using
these formulae:
- x_{window} = x_{graphics} + (MAX-1)/2
- y_{window} = (MAX-1)/2 - y_{graphics}
You "mark" points in the grid by setting the
characters in the grid, as follows:
- grid[x_{window},y_{window}] = '*';
Note that in C, arrays are stored in row-major order,
which means that Y comes before X.