# 3D Transformations of translation, scaling and rotation

## What are 3D Transformations?

- In computer graphics, 3D transformations are fundamental operations that change the
**position, size, and orientation of objects in a three-dimensional space.** - These transformations play a crucial role in creating realistic and dynamic visual scenes.

### What is Translation?

- Translation involves moving an object from one position to another in 3D space without changing its
**orientation**. - This movement is defined by a vector (dx,dy,dz), where dx, dy, and dz represent the distances the object will move along the x, y, and z axes, respectively.

**Example:**Imagine a cube initially located at coordinates (x, y, z).

If we apply a translation of (dx, dy, dz), the cube will be shifted by dx units along the x-axis, dy units along the y-axis, and dz units along the z-axis. The new position will be (x + dx, y + dy, z + dz).

**The translation matrix for a 3D vector (x,y,z) is given by:**

```
1| 1 0 0 t_x |
2| 0 1 0 t_y |
3| 0 0 1 t_z |
4| 0 0 0 1 |
```

Here, t_x, t_y, and t_z represent the translation distances along the x, y, and z axes, respectively.

### What is Scaling?

- Scaling in computer graphics is like resizing or changing the size of an image or object on a computer screen.
**Example:**Imagine you have a picture of a smiley face on your computer. If you make it twice as big, you're scaling it up. If you make it half as big, you're scaling it down.- So, you can scale things not just uniformly, but differently in width, height, or depth. It's like stretching the image in different directions.

```
1| s_x 0 0 0 |
2| 0 s_y 0 0 |
3| 0 0 s_z 0 |
4| 0 0 0 1 |
5
```

### What is Rotation?

- Rotation involves turning an object around a specified axis.
- The rotation is described by an angle θ and an axis of rotation (x, y, or z).
**Example:**Take a book lying on a table.- If we apply a rotation of 90 degrees around the z-axis, the book will appear as if it's standing upright on one of its covers.
- The pages will now be parallel to the x-y plane.

**Rotation around the x-axis:**

```
1| 1 0 0 0 |
2| 0 cos(θ) -sin(θ) 0 |
3| 0 sin(θ) cos(θ) 0 |
4| 0 0 0 1 |
5
```

**Rotation around the y-axis:**

```
1| cos(θ) 0 sin(θ) 0 |
2| 0 1 0 0 |
3| sin(θ) 0 cos(θ) 0 |
4| 0 0 0 1 |
5
```

**Rotation around the z-axis:**

| cos(θ) - sin(θ) 0 0 |

| sin(θ) cos(θ) 0 0 |

| 0 0 1 0 |

| 0 0 0 1 |

| sin(θ) cos(θ) 0 0 |

| 0 0 1 0 |

| 0 0 0 1 |

Here, θ represents the rotation angle.

### What is Shearing?

- Shearing is like giving a little push to the object, and depending on the direction, it stretches it in that particular way.
- Unlike scaling, it changes the angles between the axes, causing stretching or compression in a particular direction.
- In computer graphics, shearing is often used to create cool visual effects by distorting shapes in specific directions.

### What is Reflection?

- Reflection is a transformation that mirrors an object across a line.
- It
**changes the orientation of the object but does not alter its size**or shape. - There are different types of reflection, such as reflection across the x-axis, y-axis, or a diagonal line.

Examples:

**Reflection across the x-axis:**- Original point: (2, 3)
- Reflected point: (2, -3)
- The y-coordinate is negated while the x-coordinate remains the same.
**Reflection across the y-axis:**- Original point: (4, -1)
- Reflected point: (-4, -1)
- The x-coordinate is negated while the y-coordinate remains the same.
**Reflection across the origin (0,0):**- Original point: (-3, 5)
- Reflected point: (-3, -5)
- Explanation: Both the x and y coordinates are negated.

## What is Transformation Concatenation?

- When applying multiple transformations to an object, the order in which they are performed matters and can lead to different results.
- This concept is known as
**transformation concatenation**. Example Scenario:

- Suppose we want to move a chair represented by a 3D model:
**Translate (Move):**First, we translate the chair to the desired room location.**Rotate (Adjust Orientation):**Next, we rotate the chair to face a specific direction.**Scale (Resize):**Finally, we scale the chair to fit the room's dimensions.- If we change the order of these transformations, for instance, scaling before rotation, the chair might end up with a different orientation and size.

### Conclusion

3D transformations translation, scaling, and rotation provide the basis for creating visually appealing and dynamic 3D graphics.