2d transformations in Computer Graphics | Computer graphics
Introduction to Transformation
What is Transformation?
- Transformation refers to changing graphics, such as shifting points or resizing objects. It includes operations like translating, scaling, and rotating.
- Transformations are represented in a 2D plane.
Translation
- Translating a point involves shifting it from one position to another on the screen by adding translation values Tx and Ty to its coordinates.
- For example, if a point has coordinates (X, Y), after translation it becomes (X + Tx, Y + Ty).
- The values Tx and Ty are referred to as the translation vector.
Rotation of Points
Understanding Rotation
- Rotation involves turning a point around an origin by an angle theta.
- When rotating a point P with coordinates (x,y), the new coordinates after rotation can be calculated using trigonometric functions based on the angle theta.
Calculating New Coordinates
- The new x-coordinate after rotation is given by x' = r cos(theta + phi) , while the y-coordinate is y' = r sin(theta + phi) .
- The formulas for cosine and sine of sums are applied here:
- Cosine: cos(a+b)=cos(a)cos(b)-sin(a)sin(b)
- Sine: sin(a+b)=sin(a)cos(b)+cos(a)sin(b)
Matrix Representation of Transformations
Using Matrices for Transformations
- Transformations can be represented in matrix form. For instance:
- The transformation matrix for rotation can be expressed as:
| cos(theta) -sin(theta) |
| sin(theta) cos(theta) |
Row vs Column Major Order
- Depending on whether you use row major or column major order, the representation of transformations may vary slightly but will yield equivalent results.
Clockwise vs Counterclockwise Rotation
Direction of Rotation
- The derivation for clockwise rotation differs from counterclockwise. In clockwise rotation:
- Adjustments are made to account for negative angles when calculating new coordinates.
Final Notes on Rotational Matrices
- Both clockwise and counterclockwise rotations can be expressed using similar matrix forms; however, attention must be paid to signs in calculations depending on direction.
Scaling and Transformation in Geometry
Understanding Scaling Transformations
- The discussion begins with the derivation of transformations involving coordinates, specifically focusing on how to express changes in size through scaling.
- Scaling is defined as a transformation that alters the dimensions of an object, either expanding or compressing it. This process can be applied uniformly or non-uniformly.
- New coordinates after scaling are obtained by multiplying original coordinates (x, y) by their respective scaling factors (sx for x and sy for y).
- Uniform scaling occurs when sx equals sy, maintaining the object's proportions while changing its size.
- The effects of different scaling factors are discussed: if sx is less than 1, the object shrinks; if greater than 1, it enlarges.
Matrix Representation of Scaling
- The transformation can be represented mathematically using matrices where new coordinates (p') are derived from old coordinates (p) multiplied by a scaling matrix (S).
- An example illustrates how applying different values to sx and sy affects the size of an object during scaling.
- It’s emphasized that for matrix multiplication to work correctly, the number of columns must match the number of rows in the matrices involved.
Reflection Transformations
Basic Concepts
- Reflection is described as creating a mirror image across a specified axis. For instance, reflecting an object across the x-axis results in negative y-coordinates while keeping x-coordinates unchanged.
- Reflecting across axes alters only specific coordinate values: x remains constant while y becomes negative when reflected over the x-axis.
Advanced Reflections
- When reflecting over lines such as y = x or y = -x, both coordinates change positions or signs accordingly.
- A detailed explanation shows how reflection over these lines transforms points based on their original positions relative to those axes.
Shearing Transformations
Introduction to Shearing
- Shearing involves altering one coordinate while preserving another. For example, in x-shear transformations, only x-coordinates change while y-coordinates remain constant.
Effects of Shearing
- In shearing transformations like y-shear, only changes occur in y-coordinates which causes horizontal lines to tilt up or down without affecting their position along the x-axis.
Visualizing Shear Changes
- Diagrams illustrate how objects shift left/right or up/down depending on whether they undergo x-shear or y-shear transformations respectively.