Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that...

16
Lecture 7 2D Transformation

Transcript of Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that...

Page 1: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Lecture 72D Transformation

Page 2: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

What is a transformation?• Exactly what it says - an operation that

transforms or changes a shape (line, shape, drawing etc.) They are best understood graphically first.

• There are several basic ways you can change a shape:

• Translation (moving it somewhere else).• Rotation (turning it round).• Scaling (making it bigger or smaller).

Page 3: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Translation• Essentially, we want to move the shape dx pixels

along the x-axis and dy pixels up the y-axis. In fact all this means is moving each constituent point by dx and dy.

• To move a point in this manner, simply add the values of dx and dy to its existing coordinates. Example 15 shows what a translate() method of the Point2D class might look like.

Page 4: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Translation

Page 5: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Rotation ( about the origin)• To rotate any shape about the origin requires rotating

each of its individual points. To work out how this is done, consider the coordinates of a point before and after the rotation: Both points will lie on the perimeter of a circle of radius r with its center on the origin.

Page 6: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Rotation ( about the origin)

Page 7: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Scaling• Scaling a shape simply means making a it bigger or

smaller. We can specify how much bigger or small be means of a “scale factor” - to double the size of an object we use a scale factor of 2, to half the size of an object we use a scale factor of 0.5.

Page 8: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Scaling• Again, scaling of a shape is achieved by applying an

operation to the individual points that make up the shape. In this case, the distance of a point from the origin changes by the scale factor.

• Simply multiplying the coordinates by the scale factor gives the new values of the coordinates.

Page 9: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Scaling• Note that the scaling can be different in different

directions: i.e. the x scale factor can be different to the y scale factor. By doing this we can stretch or squeeze a shape: Simply multiplying the coordinates by the scale factor gives the new values of the coordinates.

Page 10: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Identity Transformation

Page 11: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Order of Transformation• The order in which transformations are applied to a shape is

important. e.g. performing a translation followed by a rotation, will give an entirely different drawing to a performing the rotation followed by the same translation.

Page 12: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Rotation around local origin

Page 13: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Rotation around local origin

Page 14: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Rotation around local origin

Page 15: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Review

Page 16: Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)

Exercises