Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 50 ยท Curves and Surfaces

Bezier Surfaces and Fractals

Extend curves to surfaces with bicubic Bezier patches and surfaces of revolution, then explore fractals: the Koch curve, L-systems, Mandelbrot and Julia sets.

A curve has one parameter, so it needs one number t to name a point on it. Give a shape two parameters, u and v, and you get a surface: every pair (u, v) names one point in 3D. This is how designers model car bodies, bottles and character skin without listing millions of triangles. A small grid of control points describes a smooth sheet, and the renderer cuts it into as many triangles as the screen needs.

The second half of this lesson turns to a very different way of making complicated shapes: fractals. Instead of a few control points, a fractal comes from repeating one simple rule over and over. Coastlines, ferns and the famous Mandelbrot set all grow out of it. You will build both kinds of shape in code. The curve basics you need are in Bezier curves.

Bicubic Bezier patches

A cubic Bezier curve blends four control points with the four cubic Bernstein weights:

TEXT
B0(t) = (1-t)^3     B1(t) = 3t(1-t)^2     B2(t) = 3t^2(1-t)     B3(t) = t^3

A bicubic Bezier patch does the same in two directions. It has a 4 by 4 grid of control points P[i][j] (16 in total), and the surface point at (u, v) is:

TEXT
S(u, v) = sum over i = 0..3 and j = 0..3 of  B_i(u) * B_j(v) * P[i][j]

Think of it as two steps. For a fixed v, blend each row of four points into one point, giving four points. Then blend those four with the weights in u. Because the weights always add up to 1, the result is a weighted average of the control points, so the surface never leaves the convex hull of the grid.

The properties are inherited from the curve case:

  • The four corner control points lie on the surface. The other twelve usually do not.
  • Each of the four edges of the patch is an ordinary cubic Bezier curve defined by the four control points along that edge.
  • At a corner the surface is tangent to the plane spanned by the corner point and its two neighbors.
  • Moving one control point changes the whole patch smoothly, but most strongly near that point.

A single patch is limited, so real models use many patches that share edges. If the two rows of control points on each side of a shared edge are collinear with the edge points, the neighboring patches join with a smooth tangent plane (G1 continuity), exactly like two Bezier curve segments joined in parametric curves and splines. The famous Utah teapot is a set of 32 such patches.

Surfaces of revolution

Many everyday objects are round: vases, wheels, bowls, chess pieces. A surface of revolution makes them from a flat profile curve (r(t), y(t)), where r is the distance from the axis and y is the height. Spin the profile around the y axis by an angle phi:

TEXT
x = r(t) * cos(phi)
y = y(t)
z = r(t) * sin(phi)

Use a Bezier curve for the profile and you design a vase by dragging four points. Sampling t in steps and phi in steps gives a grid of vertices, which you can join into triangles as in polygon meshes.

flowchart LR
  A["Control points<br/>(4 x 4 grid or 4 profile points)"] --> B["Sample u, v<br/>or t, phi in steps"]
  B --> C["Evaluate surface<br/>point for each pair"]
  C --> D["Join neighbors<br/>into quads or triangles"]
  D --> E["Project and draw"]

Surfaces are evaluated, not stored: the control points are small, the mesh is generated at whatever detail you need.

The demo draws both shapes as a wireframe grid. Switch the mode, drag the Bulge slider (it lifts the four middle control points of the patch, or pushes the profile outward for the vase) and spin the model with Rotate. The gray net and dots are the control points.

Bezier patch and surface of revolution

Notice that in patch mode the surface does not reach the lifted control points. At its center, each of the four middle points has weight 9/64, so together they contribute only 56% of their height (the lower edge points pull the rest down). The control net is a guide, not a skeleton the surface passes through.

Fractals: shapes with detail at every scale

A fractal is a shape that keeps showing structure when you zoom in, and is often self-similar: a small part looks like the whole. They differ from smooth curves in a precise way. Cut a line segment into 3 equal pieces and you get 3 copies at scale 1/3. Cut a square the same way and you get 9 copies. The exponent is the dimension: copies = (1/scale)^D. For a fractal that makes N copies at scale 1/s, the self-similarity dimension is:

TEXT
D = log(N) / log(s)

The Koch curve

Start with a straight segment. Replace its middle third by two sides of an equilateral triangle that point outward. You now have 4 segments, each one third as long. Repeat on every segment, forever. After n rounds there are 4^n segments of length (1/3)^n, so the total length is (4/3)^n times the original, which grows without bound, yet the whole curve fits in a finite area. Its dimension is log 4 / log 3, about 1.26: more than a line, less than a plane. Three Koch curves joined into a triangle make the Koch snowflake.

Drawing it by hand-written recursion works, but a more general tool handles it and many other fractals with the same code: the L-system.

L-systems

An L-system (named after the biologist Aristid Lindenmayer, who used it to model plant growth) is a string-rewriting game with two parts:

  1. An axiom, the starting string, and some rules such as F -> F+F--F+F.
  2. A turtle interpreter that turns the final string into a drawing.

In each round, every character is replaced at the same time by its rule (characters without a rule stay the same). The turtle then reads the string left to right:

Symbol Turtle action
F, A, B Move forward one step, drawing a line
+ / - Turn left / right by the angle
[ / ] Save / restore the position and direction (branches)
other letters (X, Y) Do nothing; they only drive the rewriting
flowchart LR
  A["Axiom<br/>F--F--F"] --> B["Rewrite every symbol<br/>by its rule"]
  B --> C{"Enough<br/>rounds?"}
  C -->|no| B
  C -->|yes| D["Turtle reads the<br/>final string"]
  D --> E["Lines on the canvas"]

The string grows exponentially, so a few rounds already give thousands of segments.

The Koch snowflake is axiom F--F--F, rule F -> F+F--F+F, angle 60 degrees. The demo below has four presets: the snowflake, the dragon curve (which folds a strip of paper in your imagination), the Sierpinski arrowhead and a branching plant. Move the Rounds slider to watch one rule produce increasing detail. The program computes the bounding box of the path and scales it to fit.

L-system turtle drawing

The branching brackets [ and ] are what let a single string describe a tree: the turtle remembers where a branch starts and comes back to continue the trunk.

The Mandelbrot and Julia sets

The most famous fractal comes from one line of arithmetic with complex numbers. A complex number z = a + bi is a point (a, b) in the plane. Pick a complex constant c and iterate:

TEXT
z(n+1) = z(n)^2 + c          with z(0) = 0

Writing z = x + yi and expanding gives two real formulas, which is all the code needs:

TEXT
x' = x*x - y*y + cx
y' = 2*x*y + cy

For some values of c the sequence stays bounded forever. For others it runs off to infinity. The Mandelbrot set is the set of all c for which it stays bounded. A useful fact makes this computable: once |z| exceeds 2, the sequence is guaranteed to escape. So the algorithm for each pixel is:

  1. Map the pixel to a complex number c.
  2. Iterate until x*x + y*y > 4 or you reach a maximum count.
  3. If you hit the maximum, treat the point as inside (paint it black). Otherwise color the pixel by how many steps it took to escape.

Each pixel is independent, which makes this an ideal workload for GPUs and for parallel code.

The Julia set uses the same formula in a different way. Fix c and let the starting value z(0) be the pixel. Every point c of the Mandelbrot plane therefore has its own Julia set. If c is inside the Mandelbrot set, its Julia set is one connected piece; if c is outside, the Julia set shatters into dust. The Mandelbrot set is a map of all Julia sets.

Click anywhere in the left picture to choose c; the right picture shows the matching Julia set, and the red cross marks your choice. Try a point near the edge of the main body, then one in a small bulb, then one far outside.

Mandelbrot map and Julia sets

Zooming into the boundary of the Mandelbrot set reveals new miniature copies of the whole set forever, which needs a higher iteration limit the deeper you go. You will build a full explorer in the fractal explorer project.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How many control points does a bicubic Bezier patch have, and which of them lie on the surface?

    A 4 by 4 grid gives 16 points. The surface interpolates the four corner points, while the inner twelve only pull the surface toward them.
  2. 2. What is a surface of revolution?

    The profile (radius, height) is rotated around the axis by an angle phi, giving x = r cos(phi), z = r sin(phi) and y = height.
  3. 3. The Koch curve replaces each segment by 4 segments of one third the length. What happens to its total length after n rounds?

    There are 4^n segments, each (1/3)^n long, so the length is (4/3)^n times the original and grows without bound.
  4. 4. In an L-system, what does the bracket pair [ ... ] let the turtle do?

    '[' pushes the turtle state on a stack and ']' pops it, so the turtle can draw a side branch and come back to the trunk.
  5. 5. What is the difference between how a Mandelbrot picture and a Julia picture use z = z^2 + c?

    Both iterate the same map. For the Mandelbrot set each pixel is a value of c with start 0; for a Julia set c is constant and each pixel is the starting value.

Summary

  • A bicubic Bezier patch is S(u, v) = sum B_i(u) B_j(v) P[i][j] over a 4 by 4 control grid; the corners lie on the surface and the whole patch stays inside the control points' convex hull.
  • A surface of revolution spins a profile curve around an axis and is perfect for round objects.
  • Surfaces are evaluated at any chosen detail and joined into triangles for drawing.
  • Fractals are generated by repeating a rule; the Koch curve has infinite length in a finite area and dimension log 4 / log 3.
  • L-systems rewrite strings and a turtle draws them; brackets create branches.
  • The Mandelbrot set collects the c values for which z = z^2 + c stays bounded; Julia sets fix c and vary the start value. Escape-time coloring paints each pixel by how fast it diverges.

Next, a completely different way to produce images: follow light backward through the scene in Ray Tracing: Rays, Spheres and Planes.