Where the unit square goes

Watching a unit square move is the easiest way to see what a matrix does.

What to build

Apply a 2×2 matrix to the corners of the unit square and report how the area changes.

Requirements

  • Read the matrix [[a, b], [c, d]].
  • Print the image of the four corners in the order (0, 0), (1, 0), (1, 1), (0, 1), one per line.
  • Print the area scale factor, the determinant a·d − b·c.

Input

Two lines: a b and c d, decimals.

Output

Five lines: four lines X Y for the image of the corners, then area scale D. All numbers have 4 decimal places.

Constraints

All numbers are between -10 and 10.

Example

Input:

2 0
0 3

Output:

0.0000 0.0000
2.0000 0.0000
2.0000 3.0000
0.0000 3.0000
area scale 6.0000

Why it works

The images of (1, 0) and (0, 1) are the two columns of the matrix, and the image of (1, 1) is their sum. The four images form a parallelogram whose area is the determinant, which is how much the matrix scales areas.

Examples

Example 1 · Input
2 0
0 3
Expected output
0.0000 0.0000
2.0000 0.0000
2.0000 3.0000
0.0000 3.0000
area scale 6.0000
Example 2 · Input
1 1
0 1
Expected output
0.0000 0.0000
1.0000 0.0000
2.0000 1.0000
1.0000 1.0000
area scale 1.0000

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

A corner (x, y) goes to (a·x + b·y, c·x + d·y).

Hint 2

The corners in order are (0, 0), (1, 0), (1, 1) and (0, 1).

Hint 3

The area of the image is the determinant a·d − b·c; print it with `:.4f`.

Solution

Show one correct solution (try it yourself first)
a, b = [float(v) for v in input().split()]
c, d = [float(v) for v in input().split()]

def r(v):
    return f"{round(v, 4) + 0.0:.4f}"

for x, y in [(0, 0), (1, 0), (1, 1), (0, 1)]:
    print(r(a * x + b * y), r(c * x + d * y))
print("area scale", r(a * d - b * c))

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Matrices as transformations →