Beginner Programming Challenge # 14

As the winner of Beginner Programming Challenge 13,

it is my turn to propose a challenge.

It will be quite mathematical but very useful for those wanting

to get into graphics/game programming but also requires some simple

text parsing.

Consider a graph on conventionalCartesianaxes.

You will be given a set of transformations to perform from a file

of 'commands'. These will be fed intostdin. When your program reaches a

line begginning 'end', it should readline of coordinates and transformone

each pair of coordinates, printing the transformed coordinates.

I will demonstrate the commands. The parts of the commands that should be taken as

variables will be enclosed in 2 $ signs like $this$. Note that in the real commands

these $ signs will no appear - they are used for clarity.

-> transform coordinates byCode:transform $a$ $b$ $c$ $d$matrix

|a b|

|c d| which is a linear transformation. ->Code:translate $x$ $y$translatecoordinates byvector

|x|

|y| ->Code:enlarge $scale_factor$enlargeby scale factor scale_factor about the origin ->Code:rotate $angle_in_rads$ clockwiserotateangle_in_radsradiansclockwise about the origin ->Code:rotate $angle_in_rads$ anticlockwiserotateangle_in_radsradiansanticlockwise about the origin ->Code:rotate deg $angle_in_degs$ clockwiserotateangle_in_degsdegreesclockwise about the origin ->Code:rotate deg $angle_in_degs$ anticlockwiserotateangle_in_degsdegreesanticlockwise about the origin ->Code:reflect y = $m$xreflectthrough straight line y=mx -> read coordinates from next lineCode:end

The coordinates line, and the printed output should be in the following format

EXAMPLE:Code:$x1$,$y1$ $x2$,$y2$, ... $xn$,$yn$

input:

output:Code:transform 1 0 0 1 translate 1 2 translate -1 -2 enlarge 2 enlarge 0.5 enlarge -1 enlarge -1 rotate 3.141592653589 clockwise rotate 3.141592653589 anticlockwise rotate deg 180 clockwise rotate deg 180 anticlockwise reflect y = 0x reflect y = 0x end 0,0 1,1 2,2 -1,-1, 0.5,0.5

I know this may seem a bit daunting but the input is easy enough to parse.Code:0,0 1,1 2,2 -1,-1, 0.5,0.5

It would be a very good idea to research 'matrix transformations', 'matrix multiplication'

and 'inverse of a 2x2 matrix'. It is likely you have not come across this area of

maths before but there are plenty of places online to look it up and the actual

algorithms are relatively simple.

Rules:

- You may use any language
AS LONG AS IT IS AVAILABLE IN THE UBUNTU REPOSITORIES

- You may use any standard libraries available with your language

unless they have specific matrix or vector functionality- You may not use any non-standard libraries
- You should provide details of how to compile/run your program
- You may ask for helps or hints if you get stuck
- Any obfusgated code or precompiled programs will not be marked

You will be marked out of 100. There will be 10 marks each available for

correctly implementing translate, enlarge, rotate, reflect and 20 marks

for correctly implementing transform. There will be 10 marks for correctly

parsing/formatting the input/output. More subjectively, there will

be up to 10 marks for each of:

- layout and commenting (use whitespace and descriptive comments)
- elegance of design (use object oriented or functional techniques)
- speed of execution (to be tested with the time command)

There may be chance for extra credit later on.

Good luck, and have fun coding!

EXTENSION TASKS:

These are worth 5 marks each, but you can't get over 100 marks.

- allow a '-c' flag to be passed that causes your calculated coordinates to be converted to the 'computer' coordinate system (by which I mean origin at the top-left hand corner and positive direction down and right). The argument after the -c flag should be the x and y coordinates of the Cartesian origin on this coordinate system, separated by a ','. eg.

puts the origin 100px right and 200px down from 0,0.Code:./program -c '100,200'- Accept an '-i' flag that prints the translation vector and transformation matrix that reverse completely all of the transformations performed from the input.

## Bookmarks