# 6.10 - Chaining Transformations (Summary)¶

The previous lesson demonstrated a robot arm with two linkages. This demonstrated how matrix transformations are chained together to create complex motion. The creation of the rendering transformations were created explicitly to make it clear how the transformations are created. Here is a summary of the transforms and the code that created them:

Eq1

*translateToPin

*rotateForearm

Eq2

*translateToPin

*rotateForearm

*translateToForearmEnd

*rotateUpperarm

Eq3

```
// For rendering the base
matrix.multiplySeries(transform, projection, view, base_y_rotate);
// For rendering the forearm
matrix.multiplySeries(transform, projection, view, base_y_rotate,
forearm_translate, forearm_rotate);
// For rendering the upper arm
matrix.multiplySeries(transform, projection, view, base_y_rotate,
forearm_translate, forearm_rotate,
upperarm_translate, upperarm_rotate);
```

## Reusing Transformations¶

Matrix multiplication is an expensive operation. For 4-by-4 matrices, multiplication requires 64 multiplies and 48 additions. We would like to avoid duplicate matrix multiplications whenever possible. For the robot arm, there is no need to repeat the same matrix multiplications over and over again. We can reuse the previous transform and simply post-multiply the additional transforms. The creation of each transform in the code could be done like this:

```
// For rendering the base
matrix.multiplySeries(transform, projection, view, base_y_rotate);
// For rendering the forearm
matrix.multiplySeries(transform, transform, forearm_translate, forearm_rotate);
// For rendering the upper arm
matrix.multiplySeries(transform, transform, upperarm_translate, upperarm_rotate);
```

Notice that in the 2^{nd} and 3^{rd} function calls the second
parameter is the value of `transform` from the previous calculation.
The following demo code contains theses simplified calculations.

Reusing transform calculations is important for complex renderings, but you should not collapse your transform calculations until you are completely clear on how to build complex chains of transformations. First, get a WebGL program to work correctly. You can always make efficiency optimizations later if slow rendering is an issue.

A robot arm rendered by re-using transforms.

-90.0 +90.0 Forearm angle: 0.00 :

-90.0 +90.0 Upper arm angle: 0.00 :

Animate