Computer Science 145.002
Introduction to Computing for Engineers
Fall 2008 / Programming Assignment 8
“Multidimensional Arrays”
Due: 7:30 AM, Thursday, November13, 2008

In this programming assignment, you will use header files to create two new classes, each of which has a two-dimensional array as its primary data member. The first of these two classes, the ImageArray class, uses a 2525 array of characters to represent a two-dimensional image. The characters used are:

  • the plus sign (‘+’), representing the origin of the x-y axes
  • the minus sign (‘-‘), representing every other part of the horizontal x-axis
  • the vertical bar (‘|’), representing every other part of the y-axis
  • the upper-case letter ‘O’, representing every part of the object whose image is being rendered
  • the blank character (‘ ‘), for all other parts of the image

The second class that you will need is the Transformation class, which uses 33 matrices to represent various two-dimensional affine transformations that may be applied to an image. There are three types of affine transformations:

Rotation

A 2D rotation about the origin may be represented by the 33 matrix

Any two-dimensional point can be rotated an angle of  by applying that matrix. For instance, to rotate the point (7.5, 3.8) by 30 degrees, you would multiply as follows:

Therefore, when the point (7.5, 3.8) is rotated 30 degrees, the point (4.595, 7.0408) is obtained.

Scaling

Scaling by a constant factor in the x-dimension and by a (possibly different) constant factor in the y-dimension may also be represented by a 33 matrix

For instance, to scale the point (7.5, 3.8) by a factor of 0.5 in the x-dimension and by a factor of 1.5 in the y-dimension, you would produce the scaled point (3.75, 5.7).

Translation

To translate a 2D point a specific amount x in the x-dimension and y in the y-dimension, the following 33 matrix would be applied:

Therefore, translating the point (7.5, 3.8) 2 units in the x-dimension and -5 units in the y-dimension would produce the point (9.5, -1.2).

The Transformation class will require initializing constructors (for the three different types of transformations: rotation will only need one double parameter, scaling will need two double parameters, and, since we’ll be translating in units of pixels, translation will need two integer parameters), as well a matrix multiplication operator, since transformations may be multiplied prior to applying them to the image being transformed, thus saving on processing.

Your driver program file will need to retrieve the contents of an ImageArray from a user-specified text file. Since each line in the file ends with white space that might be mistakenly ignored, you should use the getline functionality to retrieve this information.

Once the ImageArray is set up, the driver will need to query the user for information about which transformations need to be applied to the image. The transformations will be obtained in the order in which the user wants them applied to the image (note that applying them in a different order might produce different results). Their product is then taken and the resulting transformation matrix is ready to be applied to the image. Clearly, this approach will require that the header file for the Transformation class will need to be included in the header file for the ImageArray class.

To accomplish this, each character in the ImageArray is examined. Any that are not white space or part of the axes need to be mapped by the Transformation to their new coordinates. Unfortunately, the (row, column) format of an array doesn’t exactly correspond to the (x, y) format of two-dimensional space (which the Transformation class requires). For example, the center of the 2525 ImageArray has row 12 and column 12, but is supposed to correspond to the origin at (0, 0). To handle this, row-column information must be mapped to x-y data before applying the Transformation, and then mapped back to row-column format afterwards. Specifically,

  • For any image-related character in the ImageArray at matrix location (row, column), convert this position into a 2D location by setting the x-value to column – 12 and the y-value to 12 – row.
  • Apply the transformation to the x-y 2D location (not the row-column matrix location).
  • Convert the new x-y location into a row-column location in the transformed ImageArray by setting the row value to 12 – y and the column value to x + 12.

An example session of the completed program is illustrated at right. (Note that the limitations associated with the use of characters in this program tend to lower the quality of the transformed image.)

Name your project PA8_Lastname where Lastname is your last name (e.g., Nancy Drew’s project would be PA8_Drew). A zipped folder containing several sample input files of images is available on the course Web page at sure to include adequate explanatory comments in your code.

Zip-compress the entire project folder and place the zipped folder on your Moodledropboxby 7:30 AM on Thursday, November 13, 2008.