It’s easy to ignore the *X* output at the bottom of transform batteries in Grasshopper. What the hell are these things and why are they there? They don’t give us geometry or lists of numbers, and when hovering over the output, we can see that the data is called a *transformation matrix*. Whatever that means.

Transformation matrices can be confusing, but they are really handy for several reasons. A matrix lets a programmer clean up a series of compound linear transformations and place them into a consistent format. Because of this, matrices are widely used in computer modeling. This post will walk through how to use matrices to create quick and easy animations of complex affine transformations. And it may get a little involved, so we’re offering a user object to download at the end of this post if you want to skip to that.

Before we jump into the details, let’s talk about why we’re looking at this topic. Above is a video by Daniel Piker from 4 years ago. I remember being inspired by this short as it’s a great visualization of parametric modeling concepts. Creating animations such as these is not only eye catching, but also helps designers better understand the results of design revisions.

This video was setup in Grasshopper, and as is the case with most things in Grasshopper, the animation could have been created in a million ways. Let’s assume that the majority of animations in Grasshopper are created by animating a slider (Right click on a slider, hit animate). Applying a slider to something like a move, rotate, or scale component give us a quick and easy animation. However, there are other operations which aren’t as easy to animate. Orients, projections, box mapping, rectangular mappings, triangular mappings, and mirroring all have, let’s say, *before and after* results (it’s hard to animate with a basic slider input).

For example, it’s often cumbersome to animate through an entire sequence of steps just to orient a curved wall panel to the XY plane (like in the video above). However, if we’re able to look at the final transformation of that object (the *X* output), we can animate through that transformation and get a quick visual feedback.

To do this, we need to look at our matrices before and after the transformation. In linear algebra, a transformation matrix that applies no changes to an object is called an identity matrix. We can call this the *before *transformation matrix:

I1,I2,I3,In refer to the dimensions of the matrix (or number of rows and columns). Notice how it’s a matrix full of zeros with a 1 along the diagonal. Grasshopper uses 4×4 matrices, so we’ll have an identity matrix with four columns and four rows to start. By animating between this identity matrix and the final transformation matrix, we can create fluid animations for any affine transformation:

The image above shows the concept behind animating transformations, and the grasshopper file at the bottom of the page should provide much more helpful information regarding its setup (the above image is not actually how the definition is setup, but is just a visual showing the logic behind it).

The above video shows a torus animation and a panel animation from the Octahedron. Since a transformation matrix is compatible with all affine transformations, we’ve created a GH user object to animate through a transformation using the *X output*.

Now, with the current user object, animating these transformations will in some cases result in distorted objects during animation. Basic operations like *scale *and *translate *work with linear coefficients on transformation matrices. However, a *rotation *matrix for example uses trigonometric functions, and since the slider is a linear animation, the geometry will certainly be distorted when animating. The final rotation (or last frame of your animation) will be correct, but the geometry will distort during the animation. As an example, the matrix below shows a rotation transformation matrix about a unit vector (l,m,n):

Just something to keep in mind while animating. Regardless, this technique will help with transformations which are more difficult to animate, and should remain consistent with GH path structures in your definition.

LMNts_Transformer (171)

Disclaimer: the author does not guarantee that these parametric models are bug-free or that they will solve all of your problems. If you find bugs or have suggestions for improvements, please let us know.

Also, check out our post on Grasshopper to see a little more info. In the comments section, Daniel Piker has generously offered a script for Quarternion splining. Also, Daniel referred us to a paper regarding some issues with linear interpolation of transformation matrices (process described above).