7 Other 2D Transformations

T. Raghuveera

epgp books

 

 

Objectives:

  • To get introduced to the other useful transformations like Reflection, Shear and Transformations between coordinate systems

 

Discussion:

 

From the previous discussion it is evident that, any complex transformation can be represented as a combination of simple or basic transformations. A composite matrix that represents the complex transformation, is then derived by multiplying these basic transformations. Let’s now look at the other useful transformations: ‘Reflection’, ‘Shear’ and ‘Transformation between coordinate systems’. These transformations too can be considered as complex and they can represented as a combination of basic transformations.

 

Reflection:

 

It is similar to having an exact replica on the other side of either an axis or a plane. In 2D, we perform reflection with respect to a line or axis called ‘axis of reflection’. This axis or line can be in any orientation in 2D space. For simplicity let’s try to understand reflection with respect to the standard coordinate axes the X and Y.

 

As shown in the figure above, consider a triangle positioned in the positive quadrant, and has one of its vertices is at (4,5). Now let’s perform reflection with respect to X-axis. It is intuitive to say that, the points on both the triangles are equidistant on either side the axis of reflection (x-axis), i.e. for every point on the initial triangle there exists a point on the other side of the reflection axis that is exactly at the same perpendicular distance as that of the initial point. Consider a point (4,5), for this point, the reflection point would be (4, -5), where the y-coordinate alone is –ve, but the magnitudes remain the same. In general for any point (x, y) in the positive quadrant, the reflection point (x’, y’) with respect to X-axis will be (x, -y) We can represent this in equation form as given below.

 

X’ = X

Y’ = -Y

The equations can be represented in matrix form as below.

 

 

If we choose the reflection axis to be Y-axis, the scenario is as shown below.

 

 

Now the axis of reflection being Y-axis and the initial position of the triangle be the positive quadrant, for a point (x, y), the corresponding reflection point would be (-x, y). We can represent this in equation form as

X’ = -X

Y’ = Y

The equations can be represented in matrix form as below.

 

In general reflection can be performed with respect to any general axis in space. I we consider another axis say the Z-axis (axis passing through origin and is perpendicular to the plane containing X and Y axes), The reflection point for (x,y) will be (-x, -y). Similarly if we consider other reflection axes like Y=X and Y= -X, then for a point (x, y) in the positive quadrant, the reflection points would be (y, x) and (-y, -x) respectively. The reflection transformations and the corresponding matrices are shown below.

 

Reflection can also be performed using a rotation operation, i.e., either by rotating the object about a pivot point within the same plane by an angle of 180°CW or CCW, or by rotating the object about a pivot point, by an out of the plane movement and getting back to the plane by an angle of 180°. Now the question is, what is that pivot about which we should rotate? It is easy to say that, the pivot point lies on the axis of reflection, (for simplicity let’s consider X-axis as axis of reflection). But what could be that exact pivot point! To answer this, let’s have a look into the figures above, explaining this concept.

 

When the axis of reflection is X-axis, the pivot point for P (4, 5) shall be (4, 0) which lies on X-axis, and when the axis of reflection is Y-axis, the pivot point for P (5, 3) shall be (0,3) which lies on Y-axis. If we imagine that an object is made up of 3 vertices, and for each vertex there is a separate pivot point about which we should perform rotation, then it is quite a cumbersome task, instead we can simplify this by computing a centroid point for the object and then we need to identify a single pivot point about which all the 3 vertices are rotated. (You can do this as an exercise).

 

Exercise: Prove that reflection is rotation by 180° about some point on X-axis. (Hint: Take a point say (4, 5) and perform a rotation about (4, 0) by an angle of 180°. The same answer can be easily obtained by multiplying the point (4,5) with the reflection matrix about x-axis)

 

You may also observe that reflection by rotation within the plane of coordinate system does not give the same result as that of rotation ‘out of the plane and back into the plane’, method, even though both procedures give the same shape. Thus reflection does not alter the shapes of objects, unlike scaling.

 

If reflection is to be performed about any randomly oriented axis or line in space then you can follow these steps to solve the problem.

 

Step-1: Try to align the randomly oriented axis or line with one of the known axes say (x,y,x=y,x=-y).

Step: 2 Perform reflection with respect to the known axis.

Step: 3 Reorient the axis to its original position

 

Now for each of the above steps, derive transformation matrices, multiply all of them to get a composite transformation matrix. Multiply the vertices of the target object with the composite transformation matrix to get the final new reflected vertices.

 

**************************************************************************************************

 

Ex: Find the new reflection point for the vertex (2, 10) when reflected with respect to the axis defined by y=x+5.

Sol: For this the solution is given in the following steps

 

As we notice that the equation of the axis is of the form y=mx+c, the slope of the line ‘m’ is 1, and intercept ‘c’ is 5, that means the infinite line cuts through the y-axis at the point (0,5). As the slope ‘m’ is ‘1’, the line makes an angle 45° with x-axis (θ = Tan-1(m)). Let’s follow the simple steps given in the previous discussion.

 

i) Align the randomly oriented line with the known axes.

The sol. Is translate the line by (0,-5) such that the line passes through origin and the line coincides with the known axis X=Y (since the line has slope 1). Thus the transformation matrix for this step is

 

T (0,-5)

ii)  Perform Reflection with respect to X=Y axis using the matrix given above in the previous discussion,

 

Ref(Y=X)

 

iii)  Reorient the line such that it is back at its original position

 

T (0, 5)

 

The final step is to write the matrices in the reverse order to compute the composite matrix, as shown below.

 

P’ (x’, y’) = {T (0, 5) . Ref (Y=X) . T (0,-5)} P(x,y)

 

Shear:

 

Let’s try to understand the next transformation under discussion, the ‘shear’ transformation. Unlike reflection transformation, the shear transformation deforms the shape of the object.

 

For performing shear transformation we require 3 parameters, which are

  • Axis of shear
  • Direction of Shear
  • Magnitude of shear

Axis of shear, is the axis with respect to which the shear transformation is performed (It is also understood as the firm bottom to which the object / shape is attached). Direction of shear, is the direction in which the shear force is applied on the object /shape. Magnitude of shear is the shear force. If shear force is applied along X-direction we indicate that with the notation Shx.

In the figure shown above, the effect of shear is evident on a standard unit square at origin. The shear force is applied along X-direction so ‘direction of shear’, is the X-direction. ‘Axis of shear’ being the X-axis, and with some force the shear is applied, the effect of which is to deform the square to a parallelogram.

As can be observed from the equations above, while there is a shift in the x-coordinate by an amount Shx.y, there is no change in the y-coordinate. The net effect is distortion in shape. The shear effect can be understood better in the following discussion. Imagine you are holding a big bulky book on one of your palms with your hands stretched straight to the front, apply force on top of the book, along the forward direction with your other hand, the effect is that the top few pages of the book appear to have moved forward, while the middle pages a little forward and the bottom pages of the book show no movement. The shape is the shear effect. (The module-7 of video lecture explains this better). It can also be inferred that the effect of shear in this case, is proportional to the y-distance of the point from origin, i.e., the larger the y-coordinate of a point, the greater is the shear effect, with shx being constant.

 

The corresponding shear transformation matrix is given below.

 

Assume now a scenario, where the axis of shear is changed from X-axis to some other axis parallel to X-axis, say (yref), now what could be the effect of shear, assuming the other parameters (direction of shear, magnitude of shear) remaining the same as in the above discussion. The effect is as shown in the figure below.

 

From the above figure it can be observed that the axis of shear (a line parallel to X-axis referred to as yref) is chosen such that it is a line parallel to x-axis defined with the equation yref = -2. As mentioned before, axis of shear is understood to be the firm base to which the object is stuck. But the initial square is aligned with the coordinate axes and the bottom is shifted to align with the line yref = -2, so what could be the equations that model the shear effect? The answer is

As can be observed from the equations above, the new x coordinate (x’) has some new terms in the equation, while there are no changes in y’. The effect is that, the object not only gets sheared but also gets translated by the amount proportional to (-shx . yref). Since, yref is –ve, the translation amount becomes +ve, so the object is shifted along the +ve X-direction. If yref is chosen as positive, then the translation parameter becomes –ve, and the object shifts along the –ve X-direction. The shear transformation matrix for shear along any line parallel to X-axis given by

In general shear transformation can be performed with respect to any general line in space. In the Y-axis shear, we use xref as any general line that is parallel to Y-axis. The same set of equations can be used by just flipping x with y and y with x. Shear transformation for a standard unit square at origin, can be represented as a combination of basic transformations. It is equivalent to scaling along the diagonal followed by rotation. You can try this as an exercise!

 

Transformation between Coordinate Systems:

 

Let’s try to understand the last transformation under discussion, the ‘transformation between coordinate systems’. A transformation can be understood in either of the two ways: an object transformation or a coordinate system transformation. In object transformation, the coordinate system is assumed to be fixed while the object is transformed. Here the object assumes new coordinates after every transformation. In coordinate system transformation, objects are assumed to be stationary while the coordinate system is transformed. The end effect in both these types is the same, only that the approach differs. Whatever we have learnt so far in the discussion under the heading transformations, is fundamentally object transformations.

 

In typical graphics pipeline, a set of initial coordinates are given as input, and these coordinates are converted to a new set of coordinates by transformation i.e., from modeling to world, world to viewing, viewing to Normalized viewing and then finally to device coordinates. In coordinate system transformations, the objects assume new coordinates after every transformation, but not because the object is transformed, but because the reference with respect to which the object is defined gets transformed, i.e., when we see the same object from a new reference position or frame, the object looks different. (Remember that a coordinate system is nothing but a reference frame in space.). Let’s now understand how this transformation is performed.

 

Assume that there is an initial / base coordinate system (say) XY, with respect to which a new coordinate system X’Y’ is derived. The new / derived coordinate system has its origin at Q(x0,y0), and the X’ direction of the derived system makes some +ve angle θ with the X direction of the base system as shown in the figure below. Assume a point P(x,y) represented with respect to the base (XY) coordinate system, what would be the coordinates of the point P, if represented with respect to the derived (X’Y’) coordinate system? i.e., given a point p(x,y) with respect to Base system, what is its equivalent in the derived system?

 

Follow the steps as given below:

 

Let the equivalent coordinates for P (x,y) in the base system be, P’(x’,y’) in the derived system.

  • Translate origin of the derived such that it coincides with origin of base T(-X0,-Y0).
  • Rotate derived system such that it aligns with base system. R(-θ)
  • Find composite by multiplying the above two matrices.
  • Multiply the point P(x,y) with composite to get P’(x’,y’)

Note carefully that we should not go further to reverse the transformations as we were doing in the earlier occasions. The transformations that were used to derive the new coordinate system (say a rotation with respect to origin by an angle θ followed by a translation to position Q) are reversed to obtain the steps for this.

 

P’ (x’, y’) = {R (-θ).T (-x0, -y0)} P(x,y)

 

Thus the transformation matrix for transformation between coordinate systems can be denoted as

 

MXY->X’Y = {R (-θ).T (-X0, -Y0)}

 

Now consider a scenario as shown in the figure below, where a point P’ (x’,y’) is given with respect to the derived system. What is its equivalent with respect to the base system?

 

 

If you observe the above two ways of performing transformation between coordinate systems, the matrices MXY->X’Y’, MX’Y’->XY have the operations that are exactly in the reverse order. In practical applications, coordinates are represented with respect to the current reference frame, when transformations are to be performed, the coordinates are converted to world or the base system.

 

Summary:

  • The transformations that we have learnt in this module can be treated as complex transformations, which can be represented as a combination of basic transformations.
  • Shear transformation alters the shape of objects.
  • Reflection can be represented as rotation, shear can be represented as a combination of scaling and rotation.
you can view video on Other 2D Transformations