CS184 Lecture 25 summary

Random Fractals

Regular fractals like the von Koch curve are interesting but not very useful for modeling. On the other hand, random fractals are very good at modeling natural phenomena like terrains, water, clouds and plants.

The simplest random curve is a Brownian motion curve. For Brownian motion, a point makes a random displacement r from its previous position. The distribution of r is usually gaussian and independent in its x, y, z coordinates. A Brownian motion curve is the integral of a purely random time series.

The graph of a 1d Brownian function y = B(x), which is a 2D curve, is a reasonable depiction of a cross-section through a terrain. One way to generate the curve is to step along one point at a time, and generating the next by adding a random displacement. An equivalent way is to generate an array of random values, and then integrate it from left to right. This last method suggests a Fourier implementation. The Fourier transform of an array of independent, equally-distributed random values is an array of independent, equally-distributed random values. Integration in the Fourier domain can be done by multiplying through by 1/F, where F is the frequency.

So to generate a 1D random Brownian function, you can generate its Fourier transform by choosing the coefficient at frequency F as a random value with standard deviation proportional to 1/F. Then takes its FFT to get the Brownian curve.

Brownian terrains are a little more tricky. Integrating in 2D dimensions doesnt quite do the right thing, and its not clear that it would give an isotropic surface (one that looks the same in all directions). There is a third way to generate the 1D Brownian curve which does generalize to 2D. Consider a random step, which is a function which is constant with value -e for t < t0, and constant with value  e for t > t0. Assume t0 is chosen uniformly at random over the domain of the curve. The sum of many of these steps for small approximates a Brownian curve.

The analogue in 2D is to add many small 2D steps. Each step lies along a uniformly chosen random line in the plane. On one side of the plane the value is   -e, on the other side it is   e. Adding up many such steps gives a surface, all of whose cross-sections are 1D Brownian curves (because the cross-sections of all the 2D steps are 1D steps).

Rather than doing all of this with steps, we can use Fourier transforms instead. The transform of the sum of all the steps is a 2D set of random values whose magnitude falls of with 1/F again. Taking the inverse transform of this set gives a random terrain.

Midpoint methods

Another popular random curve generator is the midpoint method. Given an interval in x, we find its midpoint. Then we displace the midpoint in y by an amount which is random and proportional to the length of the interval. Iterating this process produces a random curve which is not the same as a Brownian curve, but is still a useful model for a terrain slice.

To generalize this method to 2D, you consider a square (say in an elevation grid). Subdivide the square into 4 squares by taking midpoints of its boundary edges. Then use the random scheme above to displace those midpoints. Finally, displace the midpoint of the entire square using the midpoint method applied to two opposite midpoints (see Hearn and Baker for a picture of this).

CSG Models

So far we have built shapes using curves and surfaces, with a few builtin VRML shapes like cylinders, blocks, cones etc. The representation of shapes using their boundaries is called the B-rep or boundary representation.

CSG or Constructive Solid Geometry is another approach to representing shapes. Rather than defining a shape in terms of the surfaces that bound it, CSG defines shapes as boolean combinations of primitive volumes. The boolean combinations are union, intersection and difference. (the set difference A - B is the intersection of A with the complement of B).

Example:

A unit cube would normally be defined by specifying its vertices, and then an indexed set of its faces. A CSG model could instead specify the cube as the intersection of 6 primitive volumes

x <= 1
x >= 0

y <= 1
y >= 0

z <= 1
z >= 0

Example 2

A closed cylinder could be specified as the intersection of an open cylinder and two half-spaces:

x2 + y2 <= 1

z <= 1
z >= 0

Often the CSG primitives will be closed cylinders and blocks rather than half-spaces like the examples above, but we chose primitives above that can be defined with a single inequality.

Testing points: CSG predicates

A CSG model is usually represented as a formula. For example, let B(p) be the formula defining a unit cube in the first example above. That is p = (x,y,z) and B is the boolean intersection of the inequalities defining the cube. So B(p) is true if and only the point p lies inside the cube.

Similarly, let C(p) be the formula defining the cylinder in example 2. Then the union of the two models (cube and cylinder) is given by the formula B(p) \/ C(p). That is, its the set of points such that either B(p) or C(p) is true.

The intersection of B(p) and C(p) is given by the formula B(p) /\ C(p), and is true of points p such that both B(p) and C(p) are true.

CSG models consist of trees of boolean combinations of primitive shapes. This is quite natural because:

When you do a new boolean operation on two CSG models, you can combine their boolean formula trees with the operation (\/ or /\ or - ) as the root node and the two model trees as left and right subtrees.

Testing lines: Ray tracing

The CSG tree can also be used to compute the intersection of the model with a line or ray. Given a line l, it is easy to compute for most primitive volumes the intersection of l with the volume. This intersection is a line segment or union of line segments. To compute the intersection of l with a CSG model, we intersect l with every primitive shape in the model and then apply the boolean operations to the set of line segments that results.

Ray-tracing can be used to compute e.g. the first intersection point of a light ray with an object. If we pass many parallel rays through an object, we can use the lengths of their intersections with the object to estimate the object's volume.

Another way to estimate volume of a CSG model A is using random sampling. Choose a bounding box BB containing the entire volume of A. Generate random points inside BB using a uniform distribution. Then test each point to see if it is in A using A's formula. Some fraction f of the points will be inside A. Then the volume of A is approximately f * vol(BB).