# Modelling

## 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 vertices (3 floats)
2. Array of faces (pointers to vertices, needs to know number of vertices)
3. Build the arrays as you read the input.

Ray tracer requires intersection tests, normal calculation.

What does the ray tracer format give?

1. Intersect a line with a plane
• Requires a vertex & the face normal
2. Normal calculation requires three consecutive vertices
• Vertices are ordered so it's easy

1. Finding the faces that surround a vertex, or the edges that emanate from a vertex
• must search linearly through the list of polygons
2. Modifying the mesh.
1. Add a vertex and a face
• easy because the user must specify the three vertices
2. Add a vertex, split a face, need to find the face.
• user specifies face (O(# of faces)) & new vertex
• overwrite old face
3. Deleting a face. ( O(# of faces))
4. Splitting or deleting a vertex
• Need to find the faces that surround a vertex.

#### Augmented Ray Tracer Format

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

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
• topology of mesh is determined by edges
• which faces are bordered by which edges

Operations we want to do

1. Faces that are neighbours of a vertex
2. Faces that are neighbours of a face
3. Vertices that are neighbours of a vertex
4. Vertices that are neighbours of a face
5. Modify the polyhedron
1. Move a vertex
2. Add a vertex, plus edges and faces
3. Add an edge between two vertices, plus faces
4. Delete various stuff, including disconnected vertices

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. pointers to the next and previous edges at each vertex
4. ```struct edge {
struct vert* v1, v2;
struct edge* nxt1, nxt2, prv1, prv2;
struct face* f1, f2;
}```

Each vertex has

1. one pointer to an edge
2. Exercise. Why do you only need one?
3. ```struct vert {
struct *edge rep;
}```

Each face has

1. one pointer to an edge
2. Exercise. Why do you only need one?
3. ```struct face {
struct *edge rep;
}```

Note. Data suppressed in the above data structures.

Exercises for the reader: Write C code that demonstrates the following.

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 (or Jerks)

Why do splines exist at all?

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

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.

For linear splines

1. Blending is the key operation.
3. Get the in-between points using P(t) = P1 + t(P2 - P1) for 0<t<1.

Linear curves necessarily give derivative discontinuities (called C1 continuity)

We can make the discontinuities unimportant by putting the points close enough together

• That is, you give me a curve I can evaluate at any points,
• I can pick points close enough together that linear interpolation between the points produces negilible derivative discontinuities.
• But how do you specify this curve?
• algebraic equation
• OR ???

The usual way is a piecewise continuous non-linear curve, with as much continuitity as you desire at the joins.

Non-linear blending

2. Blend in pairs
• P10(t) = P1 + t (P2 - P1)
• P11(t) = P2 + t (P3 - P2)
3. Blend the blend
• P20(t) = P10(t) + t (P11(t) - P10(t))
4. The result is a quadratic curve

You can take this to as many levels as you want. What does it give you? Continuity. Which is?

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

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?