# Modelling

## Particle Systems

How to use them for visualization.

1. Example. For visualizing motion in a fluid
2. Let them be carried by the fluid
3. Until the fluid flows out of the scene.

## Fractal Terrain Generation

What is it?

• A way of getting not-too-regular, not-too-random terrain,
• without positioning every vertex yourself.

How is it done?

• height at each vertex is average height + h(n) with n = 1
• h(n) is a random function with expectation zero
2. Divide each edge in two by positioning a new vertex in its middle.
• new vertex height is average edge height + h(n = n+1)
• magnitude of h(n) probably decreases with n
4. Iterate to 2 until it's good enough.

Tricks.

1. Gets expensive fast. Do as few iterations as possible.
2. Don't look directly down on it. Why?
3. h(n) will need extensive tweaking. Don't get discouraged if you don't get the results you want right away.
4. You could do the first few iterations by hand to control the large-scale result.

What is it good for?

1. Mountains
2. Rolling hills
3. Sand dunes. You will want h(n) to depend on the direction of the edge.
4. etc.

## Polyhedra and Meshes

What is a polyhedron?

1. A set of vertices
2. Connected by edges
3. Which define faces

Ray Tracer format

1. Array of edges (3 floats)
2. Array of faces (pointers to vertices, needs to know number of vertices)
3. Build the arrays as you read the input.

1. Finding the faces that surround a vertex, or the edges that emanate from a vertex
2. Modifying the mesh.
1. Add a vertex and a face, easy.
2. Add a vertex, split a face, need to find the face.
3. What's hard is finding the face to delete. ( O(nFaces) )

An improved solution

1. Build a list of faces for each vertex when reading the input
2. Can now find faces from vertices. To split a vertex
• Overwrite the deleted face with one of the new faces
• Add the other new faces to the end of the face array.
3. General deletion is still hard, unless you are willing to tolerate holes in the array.

#### Winged Edge Data Structure

When we talk about polyhedra & meshes it seems most natural to talk about vertices

• edges are vertex pairs,
• faces are vertex n-tuples n>2.

And we have been most interested in vertices and faces. Meshes are, of course, graphs

• not just any graphs but ones that obey constraints
• such as planarity
• for every constraint there is
• a conserved quantity, or invariant
• a symmetry
• complete sets of invariants are not known
• but not for lack of trying to find them

Every time we see a graph we should think,

In the dual edges are primary:

• vertices are where edges meet,
• faces are minimal closed paths

Winged edge data structure

• Where does the name come from?

Each edge has

1. pointers to the faces it separates
2. pointers to the vertices at its ends
3. participates in a doubly linked list of edges at each of its ends

Each vertx has

1. one pointer to an edge
2. Exercise. Why do you only need one?

Each face has

1. one pointer to an edge
2. Exercise. Why do you only need one?

Issues to consider

1. Traversal. Can you find all neighbours quickly?
2. Vertex/edge addition. Can you do it in constant time?
3. Vertex/edge deletion. Can you do it in constant time?

## Splines without Tears

Why do splines exist at all?

• Sometimes we absolutely need curves
• Example: specifiying fonts for SVG

The French curve.

• What am I doing with it?
• Making piece-wise curves

General piece-wise curves

1. One example is line segments: you have been making them all along.

When you put them in a mesh there is an extra requirement

• They must join at the ends: end of one must be the start of the next
• This is continuity.

But it doesn't explain why I used a French curve. Why?

Linear curves necessarily give derivative discontinuities (called C1 continuity)

• To get rid of them you need higher order curves.
• Actually third order ones.
• How does this do it?

Is it good enough to get me away from the French curve?

• Probably

Now you have a way of making smooth-enough curves specified by a small number of points.

Why is it important to have them available?