Splines, Patches and more
SPLINES As we discussed in class, the word "spline" had its origin in ship building. To create smooth hull shapes, ancient ship builders would drive pegs into the ground, and then lay down a very large thin flexible strip of wood (the "spline") that would be forced into a curve by the position of the pegs. They would then use the resulting smooth curve as a guide for cutting the lumber that they would use to create the hulls of their ships.
PARAMETRIC CUBIC CURVES The underlying math for creating smooth splines is generally to create a set of parametric cubic curves that fit together seamlessly, so that they appear to form a single smooth curve. The general recipe is as follows:
After defining the above functions x(t) and y(t), it's easy to draw the resulting spline segment. For example:
function drawSpline(x, y, dt) { let a = [x(0), y(0)]; for (let t = dt ; t <= 1 ; t += dt) { let b = [x(t), y(t)]; drawLine(a, b); // we assume this function is already defined. a = b; } }
TRANSLATING FROM THE HUMAN DESIGNER TO THE COMPUTER For most human beings, it would be extremely difficult to design such curves by directly typing the coefficients of cubic polynomials. For this reason, we create other ways of defining those coefficients, which are more human-friendly. All such methods work by transforming some easier to understand set of values into the underlying cubic coefficients (a,b,c,d). In class we have gone over several of the more important such methods, including Hermite splines and Bezier splines.
HERMITE SPLINES If our human user wants to define things in terms of the position and orientation at the beginning and end of each cubic spline segment, then we use the Hermite spline. We do all the math independently for each coordinate (eg: x and y, or x,y and z).
P0 = value at start of the segment (where t = 0). We create four "basis functions", each of which varies only one thing:
So to get from (P0,P1,R0,R1) to the coefficients (a,b,c,d) that define cubic polynomial a * t^3 + b * t^2 + c * t + d, we apply the Hermite Matrix, which is just a way of describing these four basis functions. Each of the four functions is described in a single column of the Hermite Matrix:
BEZIER SPLINES If our human user wants to define things by moving points around on a screen, then the Bezier spline is a good choice. Again, we do the math independently for each coordinate.
A = value at start of the segment (where t = 0).
In other words:
(1-t) * ( (1-t) * ((1-t)*A + t*B) + t * ((1-t)*B + t*C) ) + t * ( (1-t) * ((1-t)*B + t*C) + t * ((1-t)*C + t*D) ) When you multiply everything out, this turns into:
(1-t) * (1-t) * (1-t) * A + 3 * (1-t) * (1-t) * t * B + 3 * (1-t) * t * t * C + t * t * t * D This gives us what we need to go from key values (A,B,C,D) to cubic coefficients (a,b,c,d). Each line of the above equation can be turned into a column of the characteristic Bezier Matrix:
PARAMETRIC CYLINDERS We went over how to create a parametric cylinder. The key is to realize that the v parameter needs to go from 0 to 1 in five steps, even as the u parameter goes around in a circle (like for a sphere). Each vertex location and normal is then given by: POINT NORMAL VALUE OF V ( 0,0,-1, 0,0,-1 ) v = 0 ( c,s,-1, 0,0,-1 ) v = 1/5 ( c,s,-1, c,s, 0 ) v = 2/5 ( c,s, 1, c,s, 0 ) v = 3/5 ( c,s, 1, 0,0, 1 ) v = 4/5 ( 0,0, 1, 0,0, 1 ) v = 1where c and s stand for cos(2 π u) and sin(2 π u), respectively. An tube (or open cylinder) is much cylinder, since we need only two values of v: POINT NORMAL VALUE OF V ( c,s,-1, c,s,0 ) v = 0 ( c,s, 1, c,s,0 ) v = 1
BEZIER BICUBIC SURFACE PATCHES
For example, each point in the above patch was determined by applying a Bezier transformation to a 4x4 matrix P of 16 key points:
FUN COMPUTER GRAPHICS VIDEO At the end of Thursday's class we saw a video clip from the 1996 film Joe's Apartment.
HOMEWORK I am concerned that a number of students are falling behind. So I am going to give a week for those students to catch up. By the time our class meets on Thursday April 18, I need everyone to have completed all the homeworks through homework 7. Meanwhile, download the code that we worked on in this Thursday's class, which is in shader8.zip. For extra credit, see if you can apply the cubic spline based motion techniques in shader8 to animating elements of your own scene -- either the scene you created for homework 7, or else a new one.
|