This is the last week of my guest-lecturing in these two courses. We will cover two important topics:
(The treatment of textures will, in the case of the Interactive
Systems (COP4932) group, be pretty light-weight, because you guys
have a QUIZ during the last 45 minutes of this class.)
Let's review the basic purpose of a polygon (vs. a wire-frame.)
The polygon provides a way, for each (xs, ys) screen location, to assign some color information in such a way that the viewer believes he is seeing a spot on an actual (x,y,z) surface. The two essential facts that the polygonal data structure provides are
When people started trying to model smooth objects such as automobiles, fruit and people, they found that polygons were rather horrible to see. So they started trying to smooth them off with Gouraud and Phong shading, which worked - somewhat - for the interior areas, but which still left an unfortunate polygonal silhouette or outline, around the edges of the artificial Marilyn Monroe you were maybe trying to make.
It didn't take long for some wise folks to notice: "hey, we're computing the equation of a plane, where ax + by + cz + d = 0, ANYHOW - to get the interior points of these flat polygons. We're solving for z, then substituting in values of x and y based on inverse-transforming screen coordinates. (Sorry fellows, I left that part out due to the compressed nature of this course.)
What if we simply computed a somewhat more complex equation, like
ax**2 + by**2 + cz**2 + dxy + eyz + fzx + g = 0? What could we
represent? The answer is, lots of things - in fact, you can get
all the classical Greek curves - ellipses, hyperbolae and parabolae,
from various assignments of a, b, c, d, e, and f to that equation.
Example? x**2 + y**2 + z**2 + d = 0 describes a sphere of radius SQRT(-d), (which tells you d had better be negative.)
So, the next problem is that the world is not divided up into classical curves; it's more complex than that. The answer is, of course, like any good quilt maker, to cut the world up into sections and then model each little section with a nice polynomial of its own.
As usual, truth is a bit more complex. FIRST: We need to be able to systematically work our way across these surfaces, as we render them. But if they are at all complex, neither x, nor y, nor z, may be an appropriate dimension along which to scan. For instance, our sphere, for almost any given (x,y) pair, has TWO values of z. That could get messier if an object like a parabola was oriented at some strange angle.
SECOND: we go a little further and use CUBIC equations (with terms like x**3) rather than quadratic curves, because we have more fudge-factors (a,b,c - the coefficients) which can be adjusted, that way.
So, we simplify by complicating. We introduce two parameters called
s and t, which are regarded as metrics WITHIN the surface we're
modeling. To explain I really have to draw a picture.
In this picture, we can imagine three functions at work. X(s,t) computes the x-value for any s and t between 0 and 1. Likewise, Y(s,t) and Z(s,t) will be at work. (s,t)=(0,0) in this picture is the corner of the surface which is at (0,10,10) in Cartesian space. (s,t) = (1,1) will be at Cartesian (10,0,0).
Lines in Space. Looking at just one dimension, we see that we can make a set of polynomials for a "space-line" (that is, a rule for drawing a line through space) with three polynomials for x,y,z that look like this:
x(t) = axt**3 + bxt**2
+ cxt + d
- which is to say, there are four coefficients for determining x: a-sub-x, b-sub-x, etc. Likewise there are four for y and four for z, which gives us twelve parameters for determining this string's shape. That seems like enough "degrees of freedom". We would use six of them to locate the thing's ends, and another six to provide "tangent vectors" or arrows, telling which way the string was going when it crossed its end-points.
When we connect segments together, each one will have t running from 0 to 1. Then in the next section, t runs from 0 to 1 again (unless we get fancy; let's not.) We now consider how to join the 0 end of one string to the 1 end of another.
We define Geometric Continuity to mean "how the line looks" at the place where we join two segments together. Gzero (that's supposed to be G with a superscript of zero) means "they connect" (though they might be kinked.) G-one means that their tangents have the same direction. G-two means that the RATE OF CHANGE of the tangents does not abruptly change. Two circle segments, joined, have G-one but not G-two continuity.
We define Parametric Continuity a bit more rigorously. Czero doesn't matter. C-one means that the tangent vectors have the same direction AND magnitude at the junction. Thus if a camera were traveling along the path, with t increasing (t=time in this case), if it experienced a sudden speed-up or slow-down when crossing the junction, the path doesn't have C-one continuity even though it might have G-one.
We can express the "geometry" of a string segment with twelve numbers, being the two (x,y,z) end-points, and the two (dx, dy, dz) tangent vectors at the endpoints. We call these values P1, P4, R1 and R4, for reasons that may become clear later. Together, (P1 P4 R1 R4)Transpose (that is, the column vector containing these four little 3-vectors), is called the Hermite Geometry Matrix and can be used to generate a Hermite Curve.
"It turns out" by some calculus-based magic, that you
can produce the required polynomials for x, y and z in terms of
t, by the following matrix equation:
That is, the Hermite basis matrix M somehow converts the geometry matrix, into the coefficients of the polynomials we need. If you want to find out how M was derived, I'll show you in CAP5725.
Another popular way to write the Hermite Curve equations is as
a Blending Function. This is really just the multiplied-out results
of the above matrix equation, and looks like this:
X(t) = (2t**3 - 3t**2 + 1)*P1x + (-2t**3 + 3t**2)*P4x + (t**3
- 2t**2 + t)*R1x + (t**3-t**2)*R4x.
There are of course three sets of the above, one each for x, y and z. The x equation uses the x terms of P1, P4, R1 and R4, etc.
Bezier makes it easier. Monsieur Buzzy-a ("Bezier" to you francophones) figured out a somewhat easier geometry vector, wherein you provide four points rather than two points and two vectors. P1 and P2 define, in fact, R1 (because R1 points from P1 to P2), and P3 and P4 define R4 (because R4 points from P3 to P4.) In this case, we can see how a software package might allow the user to grab P1..P4 with a mouse and move them around to twist the curve.
The Bezier basis matrix works just like the Hermite one did, and yields slightly different blending functions. There are in fact lots of different kinds of parametric curves. The most popular ones are called NURBS (Non-uniform rational B-splines), and are covered extensively in CAP5725. But we can manage without them today.
Let's move on to the surfaces we promised you.
After that teaser with (s,t) we took an excursion into strings,
Hermite and Bezier bases, etc. Here we are back at surface land.
We will still have our parameter vectors, basic matrices and geometry
matrices, only more complex because we have to work with s and
t at the same time.
The geometry matrix is the key element here. The upper left quadrant locates the corners of the sheet. The lower left quadrant tells us how fast x is changing at all four corners, as s changes. The upper right quadrant tells us how fast x is changing at all four corners, as t is changing. So far, so cozy.
The lower right quadrant is harder to interpret. It turns out to represent the "twist" at the corners. We will let it be zero in our example.
So the geometry matrix for our example will be
and the matrix arithmetic looks like the following fine mess (actually,
not so bad.)
SO, the function we wind up with, is x(s) = 8s**3 - 7s**2. The parameter t has completely disappeared, which upon reflection is not a bad idea because in the picture, nothing about the x-value changes with t. (If we were studying the z coordinate, we would get a different but equally boring answer. What do you thing z(s,t) would look like?
Reasonableness tests: x(0,0)=x(0,1)=0, check. x(1,0)=x(1,1)=1. check.
x'(0)=0, x'(1)=10. check. (Where by x' I mean the derivative with
respect to s, which is 24s**2-14s.
A: Go and figure out the geometry matrix for the following surface. Then compute the polynomial for x, and carry out the "reasonableness checks" demonstrated above.