Presentation on theme: "Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)"— Presentation transcript:
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).
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.
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.
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.
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.
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.
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.