Next: Draw a surface plot Up: Tutorials and Examples Previous: Drawing a graph   Contents   Index

## Triangles

If you want to draw the surface of a solid object you can build it out of triangles. The graphics interface to VMD supports two types of triangles, simple triangles with just the corners defined, or "trinorms" which have normals defined for each corner.

First, a simple red triangle

```  draw delete all
draw color red
draw triangle {1 0 0} {0 1 0} {0 0 1}
```
Not bad, so let's put some more in
```  draw triangle {1 0 0} {0 1 0} {0 0 -1}
draw triangle {1 0 0} {0 -1 0} {0 0 1}
draw triangle {1 0 0} {0 -1 0} {0 0 -1}
draw triangle {-1 0 0} {0 1 0} {0 0 1}
draw triangle {-1 0 0} {0 1 0} {0 0 -1}
draw triangle {-1 0 0} {0 -1 0} {0 0 1}
draw triangle {-1 0 0} {0 -1 0} {0 0 -1}
```

And you have yourself an octahedron. See how the colors on the faces don't go smoothly from one side to the next? This is because the surface normals for one face are quite different from another, so the lights are reflected differently. The colors can be made smoother by defining the normals for the corners such that the normals of the edges are the same. One caution about defining the vertices and normals: they must be given in counter-clockwise order or the shading will be wrong.

As an example, here's the above octahedron with the normals specified:

```  draw delete all
draw color red
draw trinorm  {1 0 0} {0 1 0} {0 0 1} {1 0 0} {0 1 0} {0 0 1}
draw trinorm  {1 0 0} {0 0 -1} {0 1 0} {1 0 0} {0 0 -1} {0 1 0}
draw trinorm  {1 0 0} {0 0 1} {0 -1 0} {1 0 0} {0 0 1} {0 -1 0}
draw trinorm  {1 0 0} {0 -1 0} {0 0 -1} {1 0 0} {0 -1 0} {0 0 -1}
draw trinorm  {-1 0 0} {0 0 1} {0 1 0} {-1 0 0} {0 0 1} {0 1 0}
draw trinorm  {-1 0 0} {0 1 0} {0 0 -1} {-1 0 0} {0 1 0} {0 0 -1}
draw trinorm  {-1 0 0} {0 -1 0} {0 0 1} {-1 0 0} {0 -1 0} {0 0 1}
draw trinorm  {-1 0 0} {0 0 -1} {0 -1 0} {-1 0 0} {0 0 -1} {0 -1 0}
```

vmd@ks.uiuc.edu