Transforming Surface Models
Since surface models are just points in 3D space, it is very easy to manipulate the position and size of these models using some basic mathematical operations. These operations are collectively known as transformations.
Transformation Categories
Transformations can be broadly categorized as:
- Translation: movement along the x,y,z axes (addition or subtraction)
- Scale: enlarging or shrinking the model(multiplication or division)
- Rotation: rotation around a given vertex (transformation matrix and linear algebra)
Often, these transformations are combined. You can also warp and shear a model, but we won't get into that here.
Translating Surface Models
One of the simplest things to do with a surface model is to move the model in 3D space. For this example, we first create a surface model of a diamond.
| Create Diamond Surface model | |
|---|---|
We render the surface using the function patch.
| Render Surface | |
|---|---|

Render of a diamond surface model
To translate a surface, you simply add (or subtract) the distance to the vertices.
| Create new surface and translate | |
|---|---|
In the above code, we created a new vertices matrix, V2, by adding 2 to all vertices in V. Notice we didn't need to change the Faces matrix, F. We just modified the vertices. By adding 2 to each vertex, we translated the surface +2 in the x,y, and z directions.

Side-view render of the original (transparent) and translated diamond (solid). Here, the z is the vertical axis.

Aerial view of the same render. Bottom left render is original diamond, while top right is the translated diamond.
| Translate render using handle | |
|---|---|
The patch handle (hp2) contains the faces and vertices of the surface. When we modify the vertices in the handle, the render is instantly transformed:

Diamond translated -6 along just the z-axis
| Center surface to 0,0,0 | |
|---|---|
Sometimes, it is useful to center a 3D surface at 0,0,0. Here we center the surface by subtracting the mean of the vertices from all vertices. This works because the mean returns the centroid of the surface (its center of mass).

The surface is now centered at 0,0,0
Scaling
While translation is addition and subtraction, scaling is multiplication and division.
| Scale Diamond | |
|---|---|
The surface model is now doubled along all dimensions.

Challenge: How would you make the diamond 10x smaller?

Make Diamond Tiny
Rotation
To rotate a surface, you need a transformation matrix, our old friends sine and cosine, and some linear algebra. For those who prefer not to perform linear algebra on the fly, the required steps are encapsulated in the course function mmRotateSurfaceVertices:
| Rotate surface 90˚ around the y-axis | |
|---|---|
