### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# COMPUTER GRAPHICS COMP 360

Rice University

GPA 3.72

### View Full Document

## 6

## 0

## Popular in Course

## Popular in ComputerScienence

This 295 page Class Notes was uploaded by Cleora Stiedemann on Monday October 19, 2015. The Class Notes belongs to COMP 360 at Rice University taught by Staff in Fall. Since its upload, it has received 6 views. For similar materials see /class/224964/comp-360-rice-university in ComputerScienence at Rice University.

## Popular in ComputerScienence

## Reviews for COMPUTER GRAPHICS

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/19/15

Lecture 27 BSpline Curves and Surfaces He hath made every thing beautiful in his time Ecclesiastes 311 1 Motivation Bezier curves and surfaces are polynomials that approximate the shape defined by their control points Nevertheless Bezier curves and surfaces are not suitable for large scale industrial design and manufacture A freefonn shape such as the hull of a ship or the fuselage of an airplane or the body of a car cannot be represented accurately by a single polynomial Moreover Bezier control points have global effects see Figure l adjusting a Bezier control point near the rear of a car would affect the shape near the front of the car Designers require local control Adjusting a control point should change the shape of the curve or surface only near the control point fixing an undesirable artifact in one location should not create a new artifact in a far away location WW Figure 1 Quartic Bezier curves with five control points Changing the initial control point of the curve on the left alters the entire curve W see the curve on the right One possible alternative is to employ piecewise Bezier curves and surfaces But piecewise Bezier curves and surfaces also have drawbacks The control points for piecewise Bezier curves and surfaces that meet smoothly at their join must satisfy rigid constraints The burden of mainmining these constraints would fall naturally to the designer who may have little or no knowledge of the mathematics underlying Bezier curves and surfaces Bispline techniques overcome these shortcomings of Bezier methods Bispline curves and surfaces are inherently piecewise polynomials Moreover with Bisplines there are no constraints on the location of the control points Bisplines remain smooth no matter where the designers place their control points Bisplines also provide local control Moving a control point of a Bispline curve or surface affects the shape only in a neighborhood of the control point Parts of the shape far from a Bispline control point are not influencedby the control point see Figure 2 Figure 2 Quadratic Bispline curves with three polynomial segments and five control points Changing the initial control point of the curve on the left does not alter the second or third segments of the curve see the curve on the right Compare to the Bezier curves in Figure 1 In this lecture we are going to study B spline curves and surfaces There are many analogies between Bezier and B spline techniques Bezier curves and surfaces are polynomials B spline curves and surfaces are piecewise polynomials Bezier curves and surfaces are generated from the de Casteljau algorithm B spline curves and surfaces are generated from the de Boor algorithm Bezier curves and surfaces can be analyzed using subdivision B spline curves and surfaces can be analyzed using knot insertion The tool that unifies these two theories is blossoming so if you do not fully understand blossoming now would be a good time to review the previous lecture 2 Blossoming and the Local de Boor Algorithm The blossoming interpretation of the de Casteljau algorithm Figure 3 follows easily from the multiaffine property of the blossom Figure 4 m b V t a alt bit aat abt bbt by K 17 K 17739 Kg a dab abb bbb Figure 3 The blossoming interpretation of the de Casteljau algorithm unnormalized for cubic Bezier curves Each node in the diagram has an interpretation in terms of blossom values As usual we adopt the multiplicative notation uvw for pu v w Figure 4 The multiaffine property unnormalized of the blossom for cubic polynomials b t t a b t t a t a bgtaat aaa aab b a b a b b a d 2 The multiaffine property permits us to proceed to the next level in the diagram whenever the blossom values in two adjacent nodes agree in all but one parameter These common parameters ascend to a node in the next level of the diagram where they are joined by one new parameter The base case of the de Casteljau algorithm however is somewhat special since at the base of the de Casteljau diagram all the blossom parameters are either a or b We do not need this special base case to generate these diagrams all we require is that the blossom values in adjacent nodes agree in all but one parameter see Figure 5 If we start with n arbitrary parameters and we change one parameter at a time as we move along the base of the diagram then we arrive at the algorithm in Figure 6 This algorithm is the de Boar algorithm for one segment of a degree n B spline curve 12131 t4 f K t1 t1th l213 l4 Figure 5 The multiaf ne property unnormalized of the blossom for a cubic polynomial t t t t t t t t t 4 t1 1 t4 gt th3t 4 t1t2t3 1 t4 t1 t4 t1 t4 t1 t4 t1 t21 3t4 I47 K11 15 X12 6 K13 111213 t2t3t4 232425 t4t5t6 Figure 6 The de Boor algorithm unnormalized for one segment of a cubic B spline curve As usual we adopt the multiplicative notation uvw for puvw Compare to the de Casteljau algorithm in Figure 3 The de Boor algorithm for polynomials of degree n is generated from 211 constants t1 t2 The parameters t1 t2 are called knots These knots are not completely arbitrary because their differences appear in the denominators of the labels along the edges For example in Figure 6 3 t4 I1 is the denominator along the lower left edge and t6 I3 is the denominator along the lower right edge To avoid zeroes in the denominators we shall insist that the knots t1t2 are increasing in particular we shall insist that t1 5 s t lt t 1 5 5 t2 Also as with Bezier curves we shall want B spline curves to lie in the convex hull of their control points This constraint requires that the labels along the edges must be nonnegative for all values of t We ensure this outcome by restricting tso that t 5 ts t 1 Notice that the de Casteljau algorithm for Bezier curves of degree n is the special case of the de Boor algorithm where t1 t a and tn1quot t2nb We can blossom and homogenize the de Boor algorithm in much the same way that we blossom and homogenize the de Casteljau algorithm To blossom the de Boor algorithm replace the parameter I on the kth level of the de Boor algorithm by the parameter uk k1n see Figure 7 To homogenize the de Boor algorithm homogenize the labels along all the arrows that is replace t I gt t tjw and tk t gt tkw I see Figure 8 We shall return to the blossomed version of the de Boor algorithm in the next lecture when we study the Oslo algorithm for knot insertion In this lecture we shall use the homogeneous version of the de Boor algorithm in Section 3 to differentiate B spline curves 1M2M3 t4 143 M3 t3 t3ulquot l4uiu2 t4 V Vtz my V g t2t3M1 t3t4u1 t4t5u1 t4 V Va ISV KI my amp t3 111213 t2t3t4 t3t4t5 t4t5t6 Figure 7 Blossoming the de Boor algorithm by replacing the parameter ton the kth level of the de Boor algorithm by the parameter uk k Here we illustrate the cubic case n 3 As usual we adopt the multiplicative notation uvw for pu v w Compare to Figure 6 fff t4w ka t3tt t4ff t4w74 WW tswf t3w 1213f t3t4f t4t5f I mf Kan tsw VT 167 Kt t11213 t2t3t4 t3t4t5 t4t5t6 Figure 8 Homogenizing de Boor algorithm by replacing the labels t tj gtt th and tk t gt tkw t Again we illustrate the cubic case and as usual we adopt the multiplicative notation uvw for puvw Here t t 1 and t t w Compare to Figure 6 The control points for one segment of a B spline curve are unique To establish uniqueness fix the knots t1t2 and let Bk1 t the sum over all paths from the kth position at the base to the apex of the de Boar diagram k 11 Since every polynomial Pt has a blossom pu1u every polynomial has a representation in terms of the functions BOY t B1t In fact by construction I Pt E BkntPtk1watkn 21 k0 Thus the polynomials BoyntB quot1t span the space of polynomials of degree 11 But the polynomials of degree 11 form a vector space of dimension n1 since every polynomial of degree n can be expressed uniquely as a linear combination of the monomials 1t t Thus it follows from linear algebra that every spanning set of polynomials of order n1 is a basis for the polynomials of degree n In particular BoyntB quot1t is a spanning set of order n1 so BOY nt B n nt is a basis for the polynomials of degree n Therefore the control points of a B spline segment are unique Moreover by Equation 21 we have the following generalization of the dual functional property from Bezier curves to B splines Dual Functional Property Let Pt be one segment of a B spline curve with knots t1t2 and control points P0P Then Pk ptk1tk k0n 22 5 3 BSpline Curves and the Global de Boor Algorithm So far we have discussed only one polynomial segment of a B spline curve But a B spline curve is not just a single polynomial segment a B spline curve is a piecewise polynomial made up of many polynomial segments It is time now to usher in these additional polynomial segments For each additional B spline segment we introduce one additional knot We then shift all the indices in the de Boor algorithm by one For example introducing one new knot and shifting all the indices in Figure 6 by one generates Figure 9 m t5 t X l4 I4 15 15 X13 6 l t t4 t3t4t l4lsl t5t6t tS yv Kg 16 Kg l7 1 t t4 l2 l3l 4 g 14 5 t4t5t6 l5 id 7 Figure 9 The de Boor algorithm unnormalized for another segment of a cubic B spline curve Compare to Figure 6 Figure 6 and Figure 9 have a lot in common In fact the entire diagram below the node t4 tt see Figure 10 is common to both figures Thus we can paste these two figures together to form Figure 11 Additional diagrams can be attached to the left and to the right to join arbitrarily many curve segments z4zz t5 t z z3 1314 145 15 V2 Z67 K13 l2l3l4 l3l4l5 t4t516 Figure 10 The diagram below the node t4 It is common to both Figure 6 and Figure 9 6 ttt t3tt t4tt t5tt IVVVVVW t2t3t t3t4t m5 t5t6t t1t2t3 t2t3t4 t3t4t5 t4t5t6 t5t6t7 Figure 11 Overlaying the local de Boor algorithms unnormalized for two segments of a cubic B spline curve In Figure 11 the knots t1t7 are xed The control points are placed at the base of the diagram and the values of the B spline curve emerge at the apexes of the diagram see Figure 12 When t3 s ts t4 we compute the value at the apex on the left S3 t when t4 s ts t5 we compute the value at the apex on the right S4 t 530 S4 t r V3 57 1 14 23 4 15 W W2 5 X s lsVM 2324 223 24252 5262 4 Kn 5 W2 6X13 7 KM Po p1 p2 P3 P4 Figure 12 The de Boor algorithm for two segments of a cubic B spline curve The control points are placed at the base of the diagram and the values of the B spline curve emerge at the apexes of the diagram When t3 s ts t4 we compute the value at the apex on the left S3t when t4 s ts t5 we compute the value at the apex on the right S4 t 7 Notice that in Figure 11 we have overloaded our notation We are using the blossom value bzt3t4 to denote the control point P1 But which polynomial are we blossoming S3 t or S4 t The answer is both By the dual functional property Pk53tk1atk22tk3 k0na3 and Pk 34 tk1 tk2 tk3 k14 Thus P1s3b2t3t4 and P1s4t2t3t4 so 33t2t3t4 s4t2t3t4 Therefore we can safely use t2 t3t4 to denote P1 in fact any polynomial segment containing the control point P1 can be used to evaluate the blossom at t2 t3 t4 The same observation holds for each of the blossom values in Figure 11 where the two diagrams overlap We can choose to evaluate either 33 or 34 the values of these blossoms are necessarily identical at all the nodes common to both triangles 4 Smoothness The diagrams of the local de Boor algorithms for adjacent B spline segments fit together nicely We shall now use these diagrams to show that the corresponding B spline curve segments meet smoothly at their join By convention the parameter tfor the left segment of Figure 11 which we denote by S3 t in Figure 12 ranges over the interval t3 t4 and the parameter I for the right segment in Figure 11 which we denote by S4t in Figure 12 ranges over the interval t4t5 To show that these segments meet continuously at their join we need to investigate what happens at t t4 When t t4 the node labeled t4tt becomes t4t4t4 Since this node is common to both triangles the value of the blossom at this node must be the same for both curve segments Thus 5304214214 3404214214 But by the diagonal property of the blossom S3 t4 9304 t4 t4 and S4t4 S4 t4 t4 t4 Therefore 53 t4 S4 t4 so the two curve segments join continuously at t t4 To investigate smoothness we need to compute derivatives Recall from Lecture 26 Section 42 that for any polynomial P t n p t I W4 n k n k k P t 6quot3 31 Thus up to constant multiples derivatives are given by the homogeneous blossom evaluated at 8 t t 1 and 5 10 Using this result together with Figure 8 for the homogenous blossom we can differentiate the de Boor algorithm by replacing t w gt 5 10 Thus we can differentiate the de Boor algorithm in the same way that we differentiated the de Casteljau algorithm by differentiating the labels along the edges Figures 13 and 14 illustrate the diagrams for the first and second derivatives of the de Boor algorithm for two segments of a cubic B spline curve 14 tst rr zz 12135 mm t4t55 t5t66 t11213 W4 232425 rm t5t6t7 Figure 13 The first derivative of the de Boor algorithm for two segments of a cubic B spline curve computed by differentiating the labels on the first level of the de Boor algorithm n36 t t I4 I 3 t5 t t4 556 t455 zsaa V V 12135 mm t4t55 t5t66 t11213 W4 232425 rm t51617 Figure 14 The second derivative of the de Boor algorithm for two segments of a cubic B spline curve computed by differentiating the labels on the first two levels of the de Boor algorithm In Figure 13 at t t4 the node labeled t4t5 becomes t4t45 Since this node is common to both triangles the value of the blossom at this node must be the same for both curve segments Thus 33t4 t46 34 t4 t46 We conclude from Equation 31 that S t4 52104 so the two curve segments join smoothly at t t4 Similarly in Figure 14 at t t4 the node labeled I465 is common to both triangles so the value of the blossom at this node must be the same for both curve segments Thus 33t466 s4t455 Again we conclude from Equation 31 that S t4 52104 so the two curve segments join with two continuous derivatives at t t4 Similar arguments can be used to show that two adjacent B spline curve segments of degree n meet with 11 1 continuous derivatives at their join If a knot is repeated then the order of smoothness is reduced by the multiplicity of the knot Consider for example a cubic B spline curve with a double knot at t4 t5 Since the segment of the curve between t4 and t5 collapses to a single point we remove this segment from the de Boor algorithm Now the de Boor algorithm for the segment of the curve in the interval t3 t4 overlaps the de Boor algorithm for the segment of the curve for the interval t5 t6 only on the first level of the diagram see Figure 15 III III l l l l 3 4 IV l t t W 3 tstt t6 1 t l l t4 l 2 5 3 16X 4 77 X ls z2z3z t3t4t t4t5t tst t t6t7t Elf 41 IS kl IG KR t7 Km I87 X IS 111213 121314 131415 t4t5t6 t5t6t7 t6t7t8 Figure 15 The de Boor algorithm for two segments of a cubic B spline curve with a double knot at t4 IS 10 The arguments that we gave in the previous paragraphs for the continuity of the curve segments and their first derivatives still apply at the double knot t4 t5 since the two triangles in the de Boor algorithm overlap at the node t4t5t But the second derivatives of these curve segments will no longer match their corresponding blossoms need no longer agree at the blossom value t456 because the two triangles no longer overlap at the node t4t t Similar arguments apply to B splines of higher degree and knots with higher order multiplicity 5 Labeling and Locality in the Global de Boor Algorithm The de Boor algorithm is more complicated than the de Casteljau algorithm because the de Boor algorithm depends on the knots as well as on the control points Moreover the de Boor algorithm defines many polynomial segments whereas the de Casteljau algorithm defines only a single polynomial segment For these reasons the labels along the edges of the de Boor algorithm are more complicated than the labels along the edges in the de Casteljau algorithm Therefore before we proceed further in our study of B splines we shall pause here briefly to clarify the labeling along the edges in the de Boor algorithm Actually the labeling scheme in the de Boor algorithm is quite straightforward and easy to remember Consider a B spline curve of degree n with control points P0Pm and knots t1tm Then the label exiting Pk to the upper left is t tk and the label exiting Pk to the upper right is tkm 1 t see Figure 16 t t k tkn 1 t Pk Figure 16 Labels along the edges in the first level of the de Boor algorithm for a B spline curve of degree n The label exiting Pk to the upper left is t tk the label exiting Pk to the upper right is tkn 1 t All the other labels in the de Boor algorithm can be retrieved from these labels on the first level and the following inout property of the de Boor algorithm InOut Property Any label that enters a node in the de Boar algorithm exits the node in the same direction 11 To understand the inout property consider Figure 12 Here for ertarrple the label tel enters the node my from the lower right and ex the node my to the upper lefL Similar applies only to the numerators of the labels not to the denominators The denominators howevert Now by construction see Figure 17 the segment of a degree n Bespline curve over the paraneterinterval WM has nloonuol points 77 FNMPk depends 2 ots re ombuulm Therefore B esplines exhibit the following locality k in vesegments overtheintertal Wng up in uences solely the Zn curve segments over the interval WNW P1 P2 P5 P0 P5 P4 1 u u r 39 39 segments integers 1 8 The three polynomials segments lie over the three intervals 141145115 6 5 Every Spline is a BSpline Bespline curves are piecewise polynomials that join smoothly at the knots Conversely we shall now show that every piecewise polynomial curve where the polynomial segments meet 39 39 39 39 p39 39 Bespline This theorem is analogous to the proposition that every polynomial curve is a Beziel curve see Lecture 26 Section 3 39 39 39 39 39 39 Lemma 51 Lel Ptl and 90 bepozynommh odegree n IPWI 421 0 eyetel hell pt t 141t h e qt withquot Jor evey 52L opanlmeler him J 0 g j n he 1 r re 12 Proof Recall from Equation 31 that j n P I nDpTI65 7quot QjT n q1166 nJ Therefore 139 j P I Q rgt p171766 q1166 7quot J quot J I Now starting with the n blossom values p1 Ip116p16 6 along the base of a triangle and running the blossomed version of the homogeneous de Boor algorithm we see that the n blossom values p1 Ip1nulp1 u1u1 emerge along the left lateral edge of the triangle see Figure 18 u1142143 1 V 17 17141142 uluz V39 Y 7 w 1717141 176141 66141 VH7 V17 u 17 171717 17175 566 Figure 18 Computing the blossom values 1717171717141Iu1u2u1u2u3 from the blossom values 171717171751765 555 Notice that the first three blossom values in the first set depend only on the first three blossom values in the second set Here we use the homogeneous blossom and the identity uk uk 176 17 so no normalization is necessary in the labels along the edges But the same algorithm Figure 18 starting with the n blossom values q1Iq1I6q166 n 1 generates the n blossom values q1Iq11141q1u1u1 13 Since by assumption the input to these two algorithms is the same the output must also he the same Therefore p r 17 u1 u e q r 17 u1 u for every setofparameters u1 j V T Theorem 62 Every rpzine i a Brxpline l very pline can be repreremed a a Brxpline That ir for every Spline 51 of degree n with 05139san knot 31mm there exist Controlpoim P0Pm uch that IhESplirLE St is generated by the de Boer algorithm with eontrolpm ht P0 Pquot andmm 11 m Proof Locally every spline is a polynomial Therefore every spline has a local blossom so every spline has a local de Boor algorithm Figure 6 It remains only to show that the local de Boor algorithms for adjacent polynomial segments haveoverlapping control points as in Figures 11 and 12 Considera knot 1k By Lemma 61 the first nel derivatives ofa degree npolyuomial atthe parameter 1 1k completely determine its blossom at the values 1k u1un1 Therefore the local de Boor algorithms for adjacent polynomial segments have mauching overlapping control points Indeed by the dual functional property the control points for the polynomial segment Pkt over the interval tk1tk are PkUkenlHl1k71ipk kenllltwpsipkukl l kenel and the control points for the polynomial segment Pkglm over the interval not1 are Malaenell v Uiuipkeluk l lltIlrl ipt1 k1ii1kn Since by assumption PE on P80 it follows by Lemma 61 that ptyii1krJnelptllttyimr1ti Therefore adjacent segments have overlapping control points jeken1lk 7 Geometric Properties of Bsplirie Curves Bespline curves share several properties with Baler curves Bespline curves are affine quot quot amiatif invariant quot R r i i i i i yiuycuy 39 39 rate r r r knot is equal to the degree ofthe spline The proofs of affine invariance and the convex hull property are identical to the proofs of the corresponding results for Bezier curves simply replace the de Casteljau algorithm with the de Boor algorithm see Exercises 1 and 2 Notice that B spline curves satisfy a somewhat stronger local convex hull property each B spline segment lies in the convex hull of the control points for the corresponding segment because the parameter is restricted so that each label in the diagram for the local de Boor algorithm is nonnegative B spline curves do not in general interpolate any of their control points see Figure 17 But B spline curves do interpolate control points that correspond to knots where the multiplicity of the knot is equal to the degree of the spline To establish this result recall that by the dual functional property Equation 22 if P t is a B spline curve then Pk Ptk1a tkm Therefore if tk1 tkm then by the diagonal property of the blossom Pk Ptk1vatkn Ptk1watk1 Ptk1 Thus we can force interpolation at any control point by increasing the multiplicity of the corresponding knot Notice however that the price we pay for interpolation is to reduce the smoothness of the curve at the corresponding knot Often multiple knots are used to force interpolation at the end points of the spline where the smoothness of adjacent segments is not an 1ssue We say that a curve is variation diminishing if the number of intersections of the curve with each line in the plane or each plane in 3 space is less than or equal to the number of intersections of the line or the plane with the control polygon The variation diminishing property is important because this property guarantees that the curve does not oscillate more than its control polygon B spline curves are known to be variation diminishing but it is not so clear how to derive this result directly from the de Boor algorithm For Bezier curves we derived the variation diminishing property using subdivision For B spline curves the analogue of subdivision is knot insertion so we shall postpone our derivation of the variation diminishing property for B spline curves till Lecture 28 where we will discuss knot insertion procedures for B spline curves and surfaces 8 Tensor Product BSpline Surfaces A tensor product Bspline surface is a rectangular piecewise polynomial surface where the rectangular polynomial pieces meet smoothly along their common boundaries The construction of a tensor product B spline surface is similar to the construction of a tensor product Bezier patch see Lecture 24 Section 6 simply replace the de Casteljau algorithm for Bezier curves by the de Boor algorithm for B splines The only novelty here is the knots 15 To build a tensor product B spline surface Bs t we need a rectangular array of control points 1 i 0M j 0v and two knot sequences 31smM and t1tnv Let EU i 0M be the degree n B spline curve with control points and knots t1t v For each fixed value of t let Bs t be the degree m B spline curve for the control points P0tPM t and knots 31smM Then as s varies from Sm to SM1 and tvaries from t to IV 1 the curves Bs t sweep out a surface This surface is called a tensor product BApline surface of bidegree m n This construction suggests the following evaluation algorithm for tensor product B spline surfaces first use the de Boor algorithm M 1 times to compute the points at the parameter talong the degree n B spline curves P00 PMt then use the de Boor algorithm one more time to compute the point at the parameter 3 along the degree m B spline curve with control points P00 PMt see Figure 19 33m 34m s4 KS3 55 x Sgt gtllt 54 f kw 55 Kg 56 f X 34 gt1 S4 f Xamp 55 x 52 56 KS 34 P00 P10 P20 P3 0 P40 Figure 19 The de Boor algorithm for a bicubic B spline surface The functions P0t P4t represent cubic B spline curves in the tdirection the upper triangles represents the de Boor algorithm in 3 direction Alternatively instead of starting with the B spline curves P0t PMt we could begin with the B spline curves PsPs where Ps is the degree m B spline curve with control points PoyjPM1j and knots 31smM Now for each fixed value of 3 let Bst be the B 16 spline curve for the control points P0 sPV s and knots t1 In Again as s varies from Sm to SM1 and tvaries from t to IV 1 the curves B s t sweep out a surface and we can use the de Boor algorithm to evaluate points along this surface As with Bezier patches the surface B s t is exactly the same as the surface Bs I see Exercise 9 Tensor product B spline surfaces inherit many of the characteristic properties of B spline curves they are affine invariant lie in the convex hull of their control points and interpolate control points where the multiplicity of the knots is equal to the degree of the surface Also the polynomial patches join smoothly along common boundaries These properties follow easily from the de Boor algorithm for tensor product B spline surfaces and the corresponding properties of B spline curves see Exercise 10 To compute the partial derivatives of a B spline surface we can apply our procedure for differentiating the de Boor algorithm for B spline curves Consider Figure 19 We can compute BB Bt simply by differentiating the de Boor algorithm for each of the B spline curves P0t PM I at the base of the diagram Similarly we can compute BB BS by differentiating the first 3 level of the diagram and multiplying the result by the degree in 3 see Figure 20 Symmetric results hold for if we use the surface B SJ in place of the surface Bs t simply reverse the BB BB roles of s and t The normal vectorN to a B spline surface Bs t is given by setting N a X 3 BB BB 3 ASS V V52 33 V52 V V s3V muf n V 1 V N P60 Pl t 2 0 P00 1312 1 20 Figure 20 Computing the partial derivatives for a biquadratic B spline surface by applying the procedure for differentiating the de Boor algorithm for B spline curves To find BB Bt left simply differentiate the de Boor algorithm for each of the B spline curves P0t P1t P2t To find BB BS right simply differentiate the first level of the de Boor algorithm in s and multiply the result by the degree in s 9 NonUniform Rational BSplines NURBS B splines are piecewise polynomial curves and surfaces Polynomials and piecewise polynomials have many advantages they are easy to represent and simple to compute Nevertheless polynomials and piecewise polynomials have one severe disadvantage these functions cannot exactly represent many of the simplest bounded curves and surfaces For example there is no exact representation for the circle or the sphere with polynomials or piecewise u n l are J J functions if Pt is a polynomial then as t gt 00 the function P t gt 00 Thus polynomials cannot exactly represent bounded curves such as circles or bounded surfaces such as spheres To overcome this deficiency we shall use rational junctions that is functions that are the ratio of two polynomials For example it is easy to verify that the parametric equations 1 t2 2 t x0 2 ya 2 91 1 t 1 t represent a circle since x2 t y2t E 1 Similarly the parametric equations 1 s21 t2 1 s2 2t 2s xs t ys t zs t 92 132 1t2 132 1t2 132 represent a sphere since x2s t y2s t 123 t E 1 A rational BApline is a function that is the ratio of two B splines A nonuniform rational B spline N URB is a rational B spline where the knots are not evenly spaced Fortunately we do not need to invent any new algorithms to represent rational B spline curves and surfaces we can still use the de Boor algorithm The only change we need to make to generate rational functions is to use mass points as our control points Initially a rational B spline is a curve or surface in the vector space of mass points To generate the corresponding curve or surface in affine space we simply divide by the mass For example to construct a rational B spline curve we start with a collection of mass points mkPkmk and apply the de Boor algorithm with respect to a knot sequence t j to generate a B spline curve P tmt in the vector space of mass points We then divide by the mass mt to get the rational B spline curve Rt P t mt Rational B spline curves and surfaces inherit many of the properties of standard B splines they are affine invariant lie in the convex hull of their control points when the weights are non negative and interpolate control points where the multiplicity of the knot is equal to the degree of the curve or surface Also the rational segments join smoothly along their joins These properties follow easily from the de Boor algorithm for rational B splines and the fact that the projection into affine space is simply division which does not adversely affect any of these properties 18 Rational Bezier curves and surfaces are special cases of rational B spline curves and surfaces Again we use mass points to represent the control points but to generate rational Bezier curves and surfaces we replace the de Boor algorithm by the de Casteljau algorithm Using blossoming and the dual functional property for the denominator as well as for each coordinate in the numerator we find that the rational quadratic Bezier control points for the quarter circle represented by Equation 91 with 0 s t s 1 are given by the mass points m0P0m0 101 m1P1m1 111 m2P2m2 022 Similar techniques can be used to find the rational biquadratic Bezier control points and weights for the part of the sphere represented by Equation 92 with 0 s s t s 1 see Exercise 13 10 Summary The fundamental algorithm for B spline curves and surfaces is the de Boor evaluation algorithm The labels along the edges in the de Boor algorithm for B spline curves Figure 22 can be retrieved from the labels along the first level Figure 21 and the in out property PX Al t Pk Figure 21 Labels along the edges in the first level of the de Boor algorithm for a B spline curve of degree n 530 S40 4 V3 5 39 FM 23 14 5n zr W2 5 quot 3 fjVq 223 23242 I425 5262 4 XII 5 f W2 6 X13 7 K14 Po p1 p2 P3 P4 Figure 22 The de Boor algorithm for two segments of a cubic B spline curve The labels along the edges on first level are consistent with the labels in Figure 21 and the labels on subsequent levels satisfy the in out property 19 InOut Property 0 Any label that enters a node in the de Boor algorithm exits the node in the same direction The segment of a degree n B spline curve over the parameter interval tk tk1 has n 1 control points Pk Pk depends on 2n knots tk 1 tkm Therefore B spline curves admit local control Local Control 0 Pk in uences only the n 1 curve segments over the interval tk tkn 1 tk in uence solely the Zn curve segments over the interval tk tk Knots can have multiplicity greater than one 0 the continuity at a knot the degree of the spline the multiplicity of the knot B spline curves have the following geometric properties Af ne Invariance Convex Hull Property Variation Diminishing Property equal to the degree of the spline Tensor product B spline surfaces are an extension of the B spline representation from curves to surfaces Tensor product B spline surfaces are affine invariant lie in the convex hull of their control points and interpolate control points where the multiplicity of the knot is equal to the degree of the surface Also the polynomial patches join smoothly along common boundaries Non uniform rational B splines NURBS are the ratios of two B splines The control points of rational B splines are mass points rather than points in affine space Rational B splines are useful for representing bounded curves and surfaces such as circles and spheres which cannot be represented exactly either by polynomials or by piecewise polynomials Exercises 2 Prove that B spline curves are affine invariant Prove that each B spline curve segment lies in the convex hull of its control points 20 Interpolate control points that correspond to knots where the multiplicity of the knot is 3 Show that a B spline curve collapses to a single point P if and only if all the B spline control points are located at P 4 Show that the functions t to t tn t1t0quot tn tow t1 WWW 1 tn are the basis functions corresponding to the knot sequence t1 t t0 tn1 Note that here the knots are not increasing but the local de Boor algorithm is still valid 5 Let P0Pm be the control points for a degree n B spline curve St with knots t1 rm Show that the derivative S39 t can be computed from the de Boor algorithm for a B spline of degree n 1 with the same knots and input P P Qk k1 k tkn 1 tk1 6 Let Nk1 t denote the output of the global de Boor algorithm of degree n for the knot sequence t1 rm when the control points are given by P jyk The functions Nk1t are called the degree n Bspline basis mctions a Graph the basis functions N01t for n 123 with knots at the integers b Show that the B spline basis functions satisfy the following recurrence Nk10tl tkS tlttk1 t tk tk 1 t Nknt Nkn 1tLNkLn 1t tkn tk tk n 1 tk1 7 Let N k quot0 denote the degree n B spline basis functions defined in Exercise 6 Show that m a 2 Nkynt 51 for t 5 ts rm b 0 st U s 1 8 Let N k quot0 denote the degree n B spline basis functions defined in Exercise 6 Show that if P0 Pm are the control points for a degree n B spline curve St with knots t1 rm then In so 2 NkyntPk k0 21 9 Let N jyms denote the degree m B spline basis functions for the knot sequence 31 smM and let Nk1t denote the degree n B spline basis functions for the knot sequence t1 In see Exercise 6 Suppose that 31 i 0M j 0v are the control points for a tensor product B spline surface Bs t of bidegree m n with knots 31smM and t1 tnw a Show that M V M Bst 2 Ni1msP1l 2 2 NimsNjntPi1 i0 390i0 where t i 0 M are the degree n B spline curves with control points PlYV and knots t1tv b Show that V V M for 2 NmtP s E E NimsNnt u j0 j0i0 where PS j 0 v are the degree n B spline curves with control points PoyjPM1j and knots 31smM c Conclude that Bs t Bs t and therefore that the two constructions for the tensor product B spline surface given in the text generate identical surfaces 10 Show that tensor product B spline surfaces a are affine invariant b lie in the convex hull of their control points c consist of patches that join smoothly along common knot lines 11 Verify that the rational quadratic Bezier control points and weights for the quarter circle represented by Equation 91 with 0 s t s 1 are given by the mass points moPoam01101 m1P1m1 111 m2P2m2 Q 2 2 12 Using blossoming and the dual functional property for the denominator as well as for each coordinate in the numerator find control points and weights to represent the circle in Equation 91 as a rational quadratic B spline curve with knots at the integers 13 Find the rational biquadratic Bezier control points and weights for the part of the sphere represented by Equation 92 with 0 s s t s 1 22 Be fruitful and multiply Genesis 128 1 Vector Spaces and Division Algebras The space of mass points is a 4 dimensional vector space addition subtraction and scalar multiplication are all well defined operations on mass points But what about a more universal form of multiplication Can we multiply together two points or more generally two mass points In lower dimensional vector spaces we can indeed multiply any two elements in the space Every 1 dimensional vector space is isomorphic equivalent to the real number line We can multiply any two points along the number line by the standard rules for multiplication of real numbers Every 2 dimensional vector space is isomorphic to the plane If we identify each pair of rectangular coordinates 6117 in the plane with the complex number a bi then we can multiply two vectors in the plane using the standard rules for multiplication of complex numbers Vectors in 3 dimensions are endowed with two distinct products dot product and cross product The dot product of two vectors is a scalar the cross product of two vectors is a vector When we add or subtract two vectors we get another vector When we say that we want to multiply two vectors we typically mean that we also want the result to be another vector The dot product of two vectors is not a vector so dot product is not the kind of multiplication that we seek The cross product of two vectors is a vector nevertheless cross product also has some undesirable properties Multiplication is typically associative commutative and distributes through addition Moreover in order to solve simple equations we would like to have an identity for multiplication as well as multiplicative inverses division Although cross product distributes through addition the cross product is neither associative nor commutative Moreover there is no multiplicative identity for cross product that is there is no vector u such that for all vectors v we have uxv v X u v since by definition uxviv Hence there can be no multiplicative inverses for cross product In fact in 3 dimensions there is no entirely satisfactory notion of vector multiplication A division algebra an algebra where we can perform division is a set S where we can add subtract multiply and divide any two elements in S One exception we cannot divide by zero the identity for addition Addition and multiplication must satisfy the usual rules addition is associative and commutative multiplication is associative and distributes through addition Notice that we shall not insist that multiplication is commutative since the multiplication that we have in mind for mass points is not commutative There is an identity 0 for addition and an identity 1 for multiplication so that for any elements in S 3 0 0 s s s11ss Finally for each element 3 in S there is an inverse for addition s and an inverse for multiplication 3 1 so that s s s s 0 ss1s1s1 s 0 Thus in a division algebra we can subtract and divide as well as add and multiply There are only three nite dimensional vector spaces that are also division algebras that is there are only three dimensions in which we can de ne addition subtraction multiplication and division dimensions 124 These vector spaces correspond to the line real numbers the plane complex numbers and the space of mass points quaternions There is also a non associative multiplication in dimension 8 the Cayley numbers We are really unbelievably lucky that Computer Graphics is grounded in the 4 dimensional vector space of mass points In this lecture we shall define quatemion multiplication in the space of mass points and investigate applications of quaternion multiplication to Computer Graphics We will begin however with a simpler and better known example complex multiplication for vectors in the plane 2 Complex Numbers Addition subtraction and scalar multiplication are coordinate free operations on vectors in the plane Rectangular coordinates may be introduced in practice to perform these computations but in principle there is no need for preferred directions for coordinate axes to define addition subtraction or scalar multiplication for vectors in the plane Complex multiplication is different For complex multiplication we must choose a preferred direction the direction of the identity for vector for multiplication We denote this identity vector by 1 and we associate this vector with the x axis The unit vector perpendicular to the identity vector we denote by i and we associate this vector with the y axis Relative to this coordinate system for every vector v in the plane there are constants ab such that v a1 bi Typically we drop the symbol 1 and we write simply v a bi 21 In the complex number system i denotes 1I 1 so 12 1 22 Since 1 is the identity for multiplication we have the rules 1 39 3939 ii Therefore if we want complex multiplication to distribute through addition then we must define ab ic d i ac d ibic d i ac bdadbci 24 2 Using Equation 24 it is easy to verify that complex multiplication is associative commutative and distributes through addition see Exercise 1 Every non zero complex number has a multiplicative inverse Let v a bi The complax conjugate of v denoted by v is defined by v a bi By equation 24 vv a2b2 Ivlz Therefore Equation 24 encapsulates the algebra of complex multiplication But what is the geometry underlying complex multiplication Consider first multiplication with i If v a bi then iv ia bi bai Thus if v a b then i v ba hence i v vi Therefore multiplication by i is equivalent to rotation by 90 Also 1v abi a bi v so multiplication by 1 is equivalent to rotation by 180 There seems then to be a link between rotation and complex multiplication Let s explore this connection further Recall from Lecture 4 that the matrix which rotates vectors in the plane by the angle is given by cos sin ram sin cos Let z x y x i y be an arbitrary vector in the plane Then after rotation by the angle cos sin Znew 1 r0t x Y Sin cos or equivalently xnew x cos y sin Ynew x Sin y COS Now let w be the unit vector that makes an angle with the x axis see Figure 1 Then w cos isin and w z cos isin x iy xcos ysin xsin ycos i xnew y new Thus rather remarkably multiplying the complex number 1 by w is equivalent to rotating the vector 1 by the angle Moreover since complex multiplication is associative we can compose two rotations simply by multiplying the associated complex numbers that is for all z w 9z w w9z w 0 w w0 Representing rotations in the plane by complex numbers is more efficient than matrix representations for rotations in the plane To store one complex number we need to store only two real numbers whereas to store one 2 X 2 matrix we need to store four real numbers To compose two rotations by complex multiplication requires only 4 real multiplications whereas to compose two rotations by matrix multiplication requires 8 real multiplications Why is rotation related so closely to complex multiplication One explanation is that rotation in the plane closely resembles exponentiation because composing two rotations is equivalent to adding the corresponding angles But complex multiplication is also closely related to exponentiation Let 1 be an arbitrary complex number Define 2 z z 31 1z 2 3 Then 2 3 4 5 l l l l M 2 3 4 5 But i2 1 so substituting and collecting terms we arrive at the following fundamental identity ei 1i Euler 3 Formula 3 5 2 4 3 5 1 i cos isin 25 Since w cos isin a we conclude that w w0 ewe 9 W w a so multiplying two complex numbers of unit length is equivalent to adding the angles that these vectors form with the x axis Multiplying a complex number 1 x iy by a complex number of unit length w W1 iwz is equivalent to rotating the vector 1 by the angle arctanw2 W1 since if w lies along the unit circle there is an angle for which w cos isin see Figure 1 But what happens if we multiply z by an arbitrary complex number w If w s where s is a real number then wz sz so the effect is to scale the vector 1 by the constant s Thus both rotation and scaling can be represented by complex multiplication Finally if w W1 iwz is an arbitrary complex number then we can write w is polar form as w rem rw where r w and arctanw2 W1 Hence wz rw Z so the effect of multiplying z by w is to rotate z by the angle and to scale the result by the constant r Thus any conformal transformation of vectors in the plane can be represented by multiplication with a single complex number 2 axis w cos sin i x axis Figure 1 Multiplying a complex number 1 by a unit vector w cos sin i is equivalent to rotating the vector 1 by the angle 3 Quaternions Quaternions are just another name for the entities in the 4 dimensional space of mass points just as complax numbers are just another name for the entities in the 2 dimensional space of vectors in the plane In fact quaternions are an extension of complex numbers to 4 dimensions so we can multiply two quaternions in a manner similar to the way that we can multiply two complex numbers 5 31 Quaternion Multiplication To multiply two complex numbers we need to choose a preferred direction the direction of the identity vector for complex multiplication Similarly to multiply two quaternions we must choose a preferred mass point in the space of mass points the identity for quaternion multiplication We shall denote this special point by 0 and we will think of this point as the origin not in the 4 dimensional vector space of mass points but rather in the 3 dimensional affine space of affine points Thus 0 is a special mass point with mass m 1 The choice of the point 0 is arbitrary just as the choice of the origin is arbitrary but to perform quaternion multiplication we must fix 0 once and for all The three dimensional vectors lie in the quatemion subspace orthogonal to 0 Thus if we were to introduce rectangular coordinates into the 4 dimensional space of mass points then we would have 0 0001 and the 3 dimensional vectors v would be written as v V1V2V30 or equivalently v v1i v2j V3k where ij k are the unit vectors along the x yz coordinate axes Every mass point can be written as a scalar mass m times the affine point 0 plus a vector v For suppose that mPm is a mass point with mass m Then mPm m0 mP m m Origin m mP Origin0 Setting v mP Origin 0 we have mPmm0v 31 Interpreted in terms of coordinates Equation 31 means that every quaternion q can be written as 61 611 12 6132614 or equiValen y qq40q1iqzjq3k 32 In many texts the letter 0 is dropped and quaternions are written as 61614 I1i 6121 13k 33 In this notation a quaternion q seems to be a weird kind of hermaphrodite a scalar q4 added to a vector q1iq2jq3k In fact there are no mysterious hermaphrodites the quaternion q in Equation 33 is simply a mass point with mass 614 Quaternion multiplication is defined by setting a0 ub0vab u39v0buavuxv 34 Notice how the vector products dot product cross product and scalar product all appear in the formula for quatemion multiplication Except for the choice of the special point 0 quaternion multiplication is coordinate free since dot product cross product and scalar product are all coordinate free Using Equation 34 it is straightforward though somewhat tedious to check that quaternion multiplication is associative and distributes through addition see Exercise 6 Notice however that quatemion multiplication is not commutative since cross product is anticommutative The point 0 is the identity for quaternion multiplication because by Equation 34 0b0v b0v 6 In particular 02 0 Similarly it is easy to verify from Equation 34 that the basis vectors i j k multiply according the the following rules i2 j2 k2 0 and ij k ji jki kj kij ik 35 More generally if uv are 3 dimensional vectors then by Equation 34 uv u39v0ugtltv Thus the product of two vectors uv in 3 dimensions is a 4 dimensional mass point with mass m u 39 v In particular 142 u39u0 u2 0 1 u Iul2 Every non zero quaternion has a multiplicative inverse Let q mq 0 vq The conjugate of q denoted by 61 is defined by 61 mq 0 vq By equation 34 6161 m vq 39vq0 But recall that in quaternion space quO so by the Pythagorean theorem m2v39v2 q q q 139 Hence qq q I2 0 36 Therefore 1 61 1 2 Iq In terms of coordinates if q q1 q2 613614 then q 6140 611i 6121 613k 61 6140 q1i qzjqak q2q12q q32q3 Later on we shall also need the following result Lemma 1 pq qp Proof Let p mpOvp and qmq0vq Then pqmp0vpmq0vq mpmq vp 39vq0mqvp mpvq vp qu qp mq0vqmp0vpmqmp vq vp0 mqvp mpvqvqva Comparing the right hand sides of these two equations and recalling that the cross product is anticomrnutative we conclude that 1760 6137 With this brief introduction to quaternion algebra we are now ready to turn our attention to the geometric applications of quaternion multiplication 32 Quaternion Representations for Conformal Transformations Quaternion multiplication can be used to model rotations of vectors in 3 dimensions much like complex multiplication can be used to model rotations of vectors in the plane In fact quaternion multiplication can be used to model any conformal transformation rotation mirror image and uniform scaling of vectors in 3 dimensions The key to modeling conformal transformations with quaternions is sandwiching Let q be an arbitrary quaternion and let v be an arbitrary vector Define Sqv q v q 37 Equation 37 is called sandwiching because the vector v is sandwiched in between the quaternions q and 61 Notice that Sp oSqv Spqv 38 because by Lemma 1 Sp o sqxv spsqv Spq v cf p q v qp p q v pq Spqw Proposition 2 Let qN cos 20 sin 2N Then a vector v can be rotated around the axis N through the angle by sandwiching v between qN and qN Proof By the formula of Rodrigues Lecture 12 if we rotate a vector v around the axis N through the angle then vnew cos v 1 cos v NN sin N x v Thus we need to show that sandwiching v between qN and qN yields the same result To proceed let vH and vi be the components of v parallel and perpendicular to N Then 8 yum0 e NyueewN0VHN yyNeo NviNxvieviN To simplify oni uo39a 39ou let c cos 2 siu 2 and q qN CON Now vqxCONVHVJCOrN czvllrsszllNcNvHrWNc NvirviNszir2NlLN W 0 2Nu2Nxvi czvurn2NNlH4r 2cmva c2yy nzNNyi ButsiuceN is a nuitvecwr 70 Hence qu c2ZVHzenvauwzeszwi By the half angle formulas for sine and cosine Exercise 3 2csin 02 72 cos Hence 7qu W COS Vl 5i NgtltVJ 1COS W COS Vl W siu NX l Finally V Vl W Nxv NxvuviNxvi N39v N 39WHU N 39W W NNVH Z NNVHN 39VllW N 39VN qu cos v lrcos XN 39vN siu N x y Nance Lhatthe quatemiou qN is a unit quatemiou because by Equation 36 x 2 2 blN 20qN qN cos 2sm 200 Thus every icmion is represented by a unit quatemiou Ccnyeisely every unit quatemiou represems a tendon because if q mq 0 vq is a nuitquamruiou then mq lvq 1 Hence there is an angle 6 and a unit Vector N such that mq cos9 and vq siu6N so q cos60 siu6N e qN 26 To model mirror image with sandwiching observe that to find the mirror image of a vector v in the plane perpendicular to the unit normal vector N we can rotate v by 1800 around N and then negate the result But qN7r cos7r 20 sin7r 2N N Thus to rotate v by 1800 around N we can sandwich v between N and N Since for vectors N N it follows that mirror image of v in the plane perpendicular to N is given by S N v N vN To verify this result recall from Lecture 12 that under mirror image vnew v 2v 39NN Proposition 3 SNv NvN v 2v 39NN Thus v can be mirrored in the plane perpendicular to the unit normal N by sandwiching v with N and negating Proof SNv N v N N39v0 NxvN N39vN Nxv39N0NgtltvgtltN a 0 N39vNN39Nv N39vN v 2N39vN Proposition 4 S1500 cv Thus v can be scaled by the factor 0 by sandwiching v with 150 Proof 45001 JLTOV1LTOCV Theorem 5 Every conformal transformation of vectors in 3dimensions can be modeled by sandwiching with a single quaternion Proof This result follows from Propositions 234 since by Equation 38 composition of sandwiching is equivalent to multiplication of quaternions Conformal transformations of vectors in 3 dimensions can be computed by sandwiching the vectors with the appropriate quaternions But what about conformal transformations on points in 3 dimensions To rotate points about arbitrary lines or to mirror points in arbitrary planes or to scale points uniformly about arbitrary points we cannot simply sandwich the points we wish to transform with some appropriate quaternion see Exercise 19 Recall however that rotation mirror image and uniform scaling all have a fixed point Q of the transformation Since P Q P Q we can compute conformal transformations on affine points P by using quaternions to transform the vectors P Q and then adding the resulting vectors to Q In this way quaternions can be applied to compute conformal transformation on points as well as on vectors 10 33 Quaternions vs Matrices We now have two ways to represent conformal transformations on vectors in 3 dimensions 3 X 3 matrices and quaternions Here we shall compare and contrast some of the advantages and disadvantages of quaternion and matrix representations for conformal transformations A 3X3 matrix contains 9 scalar entries whereas a quaternion can be represented by 4 rectangular coordinates Thus if memory is at a premium quaternions are more than twice as efficient as matrices On the other hand by Equation 34 to compute the product of two quaternions requires 16 real scalar multiplications 6 for the cross product 3 for the dot product 6 for the two scalar products and one for the product of the two scalar masses Similarly since a vector has zero mass the product of a quaternion and a vector requires 12 scalar multiplications since the product of the masses as well as one of the scalar products is zero Sandwiching a vector with a quaternion computes a product of a quaternion with a vector followed by the product of a quaternion with a quaternion so the total cost for one conformal transformation using quaternions is 12 16 28 scalar multiplications whereas the cost for multiplying a vector by a 3 X 3 matrix is only 9 scalar multiplications Thus matrices are more than 3 times as fast as quaternions for computing arbitrary conformal transformations But there is an additional computational consideration To compose two transformations by quaternion multiplication requires 16 scalar multiplications whereas to compose two transformations by matrix multiplication requires 27 scalar multiplications Therefore quaternion multiplication is more than 15 times faster than matrix multiplication for composing conformal transformations Thus some computations favor quaternions whereas others favor matrices We summarize these tradeoffs for both memory and speed in Table 1 memo transformation composition quaternions 4 scalars 28 multiplies 16 multiplies 3 X 3 matrices 9 scalars 9 multiplies 27 multiplies Table 1 Tradeoffs between speed and memory for quaternions and 3 X 3 matrices 34 Avoiding Distortion Aside from considerations of memory and speed one of the main advantages of quaternions over matrices is avoiding distortions that arise from numerical inaccuracies that are inevitably introduced by floatin g point computations For any 3 X 3 matrix A representing an affine transformation 1new 1 LjnewJ knew k Since the matrix with rows i j k is the identity matrix we conclude that inew A jnew 3399 knew Hence the rows of A represent the images of the unit vectors i j k along the coordinate axes Thus if a 3X 3 matrix A represents a conformal transformation then the rows of A must be mutually orthogonal vectors since conformal transformations preserve angles and the original vectors i j k are mutually orthogonal To compose conformal transformations we must multiply matrices But the entries of these matrices especially rotation matrices which contain values of sines and cosines are typically represented by oating point numbers Therefore after composing several conformal transformations the rows of the product matrix will no longer be mutually orthogonal vectors due to numerical inaccuracies introduced by floating point computations Thus these matrices no longer represent conformal transformations so applying these matrices will distort angles in the image Quaternions avoid this problem To compose conformal transformations we multiply the corresponding quaternions Since every quaternion represents a conformal transformation computing transformations by sandwichin g with quatemions will never distort angles Suppose however that we want to compose only rotations Composing rotations by matrix multiplication we will generate distortions in both lengths and angles due to numerical inaccuracies introduced by floating point computations We need to renormalize the resulting matrix so that the rows are mutually orthogonal unit vectors but it is not clear how to perform this normalization This normalization however is easy to perform with quatemions Rotations are represented by unit quaternions When we compose rotations by multiplying unit quatemions the result may no longer be a unit quaternion due to floating point computations But we can normalize the resulting quaternion q simply by dividing by its length lq The resulting quaternion q ql is certainly a unit quaternion so this normalization avoids distorting either lengths or angles in the image 35 Key Frame Animation Quaternions have one additional advantage over matrices quaternions can be used to interpolate in between frames for key frame animation In key frame animation an artist draws only a few key frames in the scene and an animator must interpolate intermediate frames to make the animation look natural Consider an object is tumbling through a scene An artist will typically draw only a few frames representing rotations of the object at certain key times An animator must then find intermediate 12 rotations so that the tumbling appears smooth Suppose that from the artist s drawing we know the rotations R0 and R1 at times t 0 and t 1 How do we find the appropriate intermediate rotations at intermediate times If the rotations R0R1 are represented by 3 X 3 matrices then we seek intermediate rotation matrices Rt for 0 lt t lt 1 We might try linear interpolation and set Rt 1 tR0 tRl The problem with this approach is that the matrices Rt are no longer rotation matrices because the rows of these matrices are no longer mutually orthogonal unit vectors Thus the matrices Rt will introduce undesirable distortions into the animation Alternatively we could use unit quaternions 610611 to represent these two rotations The quaternion generated by linear interpolation 610 1 t610 11 is no longer a unit quaternion but we can adjust the length of qt by dividing by qt Now qt qt is a unit quaternion representing an intermediate rotation Unfortunately the tumbling motions generated by this approach will not appear smooth because linear interpolation does not generate uniformly spaced quaternions that is if is the angle between 610 and q1 then t is not generally the angle between qo and qt qt To correct for this problem we apply spherical linear interpolation SLERP see Lecture 11 that is we set sin1 t sint W0 sinw where is the angle between qo and q1 Recall that SLERP guarantees that if qo and q1 are unit qt slerpq0q1 t q1 310 quaternions then qt is also a unit quaternion and if is the angle between 610 and q1 then t is the angle between 610 and qt Thus spherical linear interpolation applied to quaternions generates the appropriate intermediate rotations for key frame animation 36 Conversion Formulas Since we have two ways to represent conformal transformations on vectors in 3 dimensions 3 X 3 matrices and quaternions and since each of these representations is superior for certain applications it is natural to develop formulas to convert between these two representations If a quaternion represents scaling along with rotation the scale factor can be retrieved from the magnitude of the quaternion Similarly if a 3X3 matrix is a composite of rotation and uniform scaling the scale factor can be retrieved from the determinant of the matrix Therefore we can easily retrieve these scale factors and we can always normalize quaternions to 13 have unit length and conformal matrices to have unit determinant Unit quaternions and 3X3 conformal matrices with unit determinant represent rotations Since as we have just seen in Sections 34 and 35 rotations embody the most important applications of quaternions to Computer Graphics we will concentrate here on converting between different representations for rotations Consider a rotation around the unit axis vectorN by the angle The rotation matrix Lecture 13 and the unit quaternion Section 32 Proposition 2 that represent this rotation are given by R0tN cos I 1 cos NT N sin N X 311 qN cos 20 sin 2N 312 To convert between these two representations for rotation we shall make extensive use of the following half angle and double angle formulas for sine and cosine see Exercise 3 cos2 2 m 2 sin2 2 sin 2sin 2cos 2 Suppose that we are given the rotation matrix R0tN cos I 1 cos NT N sin N gtlt RI1 and we want to find the corresponding unit quaternion qN cos 20 sin 2N Then we need to find cos 2 and sin 2N Expanding Equation 311 in matrix form yields cos 1 cos N12 1 cos N1N2 sin N3 1 cos N1N3 sin N2 R0tN 1 cos N1N2 sin N3 cos 1 cos N22 1 cos N2N3sin N1 1 cos N1N3 sin N2 1 cos N2N3 sin N1 cos 1 cos N 313 Since N is a unit vector N12N22N32 N39N1 Therefore summing the diagonal entries of R0tN gives R111 R212 R313 3 cos 1 cos 1 2cos Solving for cos we nd that R111R212 R313 1 cos 2 314 But by the half angle formula cos 2 quotg Therefore by Equation 314 R R 1 cos 2m 315 To find sin 2N observe from Equation 313 that 2sin N R23 R312R311 R113R112 R211 316 But sin 2ampin 2cos 2 Substituting this result into Equation 316 and solving for sin 2N yields R23 R32R31 R13 R12 R21 4cos 2 39 Thus by Equations 315 and 3 17 R11R22R331 R R R y 2 1 0 23 32 31 13 12 21 I 2 VIR111R212 R313 1 sin 2N 317 318 Conversely suppose that we are given the quaternion qN cos 20 sin 2N q1q2q3q4 319 and we want to nd the matrix R0tN cos I 1 cos NT N sin N X Then we need to compute the three matrices cos I 1 cos NT N Sin N X By the half angle formula cos 2cos2 2 1 Thus by Equation 319 since qN is a unit quaternion 2 2 2 2 2 cos 2614 1 614 611 612 613 2 2 2 2 Q4 Q1 Q2 Q3 0 0 2 2 2 2 cos I 0 614 ql q2 q3 0 320 2 2 2 2 0 0 Q4 Q1 Q2 Q3 Moreover since by the half angle formula sin2 2 it follows that 1 cos NT N 2sin 2NT sin 2N Hence by Equation 319 1 cos gtltNT N 20114243 Q12Q22Q3 26112 2611612 2611613 1 cos NT N 2m2 2qu2 2q2q3 321 2611613 2612613 261 Finally since sin 2sin 2cos 2 we have sin N 2sin 2cos 2N Hence again by Equation 319 Sin N 2Q4Q1 Q2 Q3 0 2Q4Q3 2Q4Q2 Sill N X 2Q4Q3 0 2Q4Q1 322 L 2Q4Q2 2Q4Q1 0 J Adding together Equations 320 321 322 yields 2 2 2 2 Q4 Q1 Q2 Q3 2Qin 2Q3Q4 2Q1Q3 2Q2Q4 2 2 2 2 R0tNa 2Q1Q2 2Q3Q4 Q4 Q1 Q2 Q3 2Q2Q3 2Q1Q4 323 2 2 2Q1Q3 2Q2Q4 2Q2Q3 2Q1Q4 Q4 Q1 Q2 Q3 4 Summary Complex numbers can be used to represent vectors in the plane A vector 1 x y in the xy plane can be rotated through the angle by multiplying the complex number 1 x i y with the complex number w em cos isin which corresponds to the unit vector that makes an angle with the x axis Similarly the vector 1 x y can be scaled by the factor 3 by multiplying the complex number 1 x yi by the real number 3 Thus every conformal transformation of vectors in the plane can be represented by multiplication with a single complex number w W1 iwz where s w is the scale factor and arctanw2 W1 is the angle of rotation Quaternions are complex numbers on steroids Quaternion multiplication is an extension of complex multiplication from the 2 dimensional space of vectors in the plane to the 4 dimensional 16 space of mass points The product of two quaternions incorporates dot product cross product and scalar product and is given by the formula a0 ub0v ab 1439 v0 bu av uxv where 0 represents the origin of the points in 3 dimensional affine space Quaternion multiplication can be used to model conformal transformations of vectors in 3 dimensions by sandwiching a vector v between a quatemion q and its conjugate 61 Sq v q v q In particular we have the following formulas for rotation mirror image and uniform scaling Rotation around the unit direction vector N by the angle qN cos 20 sin 2N SqN v qN v qN Mirror Image in the plane perpendicular to the unit normal N S N v N v N Uniform Scaling by the scale factor c S 46 0 v cv Quaternions provide more compact representations for conformal transformations than 3X 3 matrices since quaternions are represented by 4 rectangular coordinates whereas 3X3 matrices contain 9 scalar entries Composing conformal transformations by multiplying quaternions is faster than composing conformal transformations by matrix multiplication because to compute the product of two quaternions requires only 16 real scalar multiplications whereas to compose two transformations by matrix multiplication requires 27 real scalar multiplications Nevertheless quaternions are not a panacea The total cost for computing one conformal transformation on a vector using quaternions is 28 scalar multiplications whereas the cost for multiplying a vector by a 3X3 matrix is only 9 scalar multiplications Thus matrices are more than 3 times faster than quaternions for computing conformal transformations Quaternions are used in Computer Graphics to avoid distortions that can arise during conformal transformations due to numerical inaccuracies introduced by floating point computations Quaternion transformations never distort angles because every quatemion represents a conformal transformation Moreover unlike 3 X 3 matrices quaternions are easily normalized so unit quaternions can be employed to avoid distorting distances as well as angles during rotation Quaternions are also used in Computer Graphics to perform key frame animation In key frame animation an artist draws only a few key frames in the scene and an animator must then interpolate intermediate frames to make the animation look natural Linear interpolation of rotation matrices does not generate rotation matrices Linear interpolation of unit quaternions does not generate unit quaternions and even when normalized the resulting unit quaternions are not uniformly spaced along an arc in 4 dimensions so the resulting motion appears jerky rather than smooth To interpolate smoothly between two rotations represented by the unit quaternions q0 q1 we apply spherical linear interpolation sin1 t sint sin 10 sin where is the angle between qo and q1 Spherical linear interpolation avoids undesirable artifacts 513016102611 0 11 that arise from interpolation methods that either fail to generate rotations or build rotations that do not transition smoothly between the artist s original rotations Unit quaternions qN q1q2q3q4 and 3X3 matrices R0tN RI1 can both be used to represent rotations around the unit axis vectorN by the angle The following formulas can be applied to convert between these two representations 1 R11 R22 R33 1 R2 3 R3 2i R31 R1 3 R12 R2 0k 61N 2 0 2 1121 R212 R313 1 2 2 2 2 614 611 612 613 2611612 2613614 2611613 2612614 2 2 2 2 R0tNa 2611612 2613614 614 611 612 13 2612613 2611614 2 2 2 2 2611613 2612614 2612613 2611614 14 611 12 13 Exercises 1 Using Equation 24 verify that complex multiplication is associative commutative and distributes through addition 2 Let r denote the polar coordinates of a point in the plane Show that in polar coordinates complex multiplication is equivalent to 1101 7292 1201 02 3 Here we shall derive the half angle formulas used in the text a Using Euler s formula Equation 25 show that cos2 isin2 cos isin 2 18 9 Conclude from part a that i cos2 cos2 sin2 2cos2 1 ii sin2 2sin cos c Conclude from part b that i cos 2 W W 2 ii sin 2 4 Let z x y x iy be an arbitrary vector in the plane and let w cos 2 isin 2 a Show that z r0t w z w b Conclude that a vector 1 in the plane can be rotated through the angle by sandvviching 1 between w and w 5 Let wlw2w be complex numbers and let pz anz do be a polynomial in the complex variable 1 with real coefficients 10 a a Show that i W1 w2 w w ii w1w2 wfw iii w w b Conclude from part a that if pw 0 then pw 0 6 Using Equation 34 and the properties of dot product and cross product verify that quaternion multiplication is associative and distributes through addition 7 Let abxy be real numbers and let zl a bi 12 x yi be complex numbers a Verify Brahmagupta s identity at2 172x2 y2 ax by2 ay bx2 b Using Brahmagupta s identity prove that Izlzzlz1z2 8 Let abcdwxyz be real numbers and let q1 abicj dk q2 w xi yj zk be quaternions 11 12 a Verify the following generalization of Brahmagupta s identity 2 2 2 2 2 2 2 2 2 2 a 17 0 d w x y z aw bx cy dz axbwcz dy ay bzcw dx2 azby cx dw2 b Using the result in part a prove that 39611 1239quot11quot 1239 Consider a quaternion q 6100 ql i qz j 613 k a Show that q 6100 110 6120 613011 b Conclude from part a that every quaternion can be represented by a pair of complex numbers c Let ahc d be complex numbers Show that abJc dj ac bdadbcj Let q be an arbitrary quaternion Define 2 eq 0q q 2 3 a Show that if N is a unit vector then eAN cas 0 sintN b Conclude from part a and Proposition 2 that v can be rotated around a unit vector N N2 e N2 through the angle by sandwiching v between q e and 61 Consider two unit vectors v0v1 Let be the angle between v0 and v1 and let w a Using the results of Exercise 10 show that O 1 i slerpv0v1 t emWZ v0 mum ii va0 e w b Conclude from part a that l2 slerpv0v1t vaOYZ v0v3v1 Let p p40p1i p2jp3k and q q40q1iq2jq3k Showthat M 174614 131611 132612 1336190 174611 p1q4i 174612 p2q4j 174613 173614 k P2513 P3612 P3611 171613 P1612 P2611k 20 13 Let p p1p2p3p4 and q 611612 613614 be quaternions and let 44 43 42 41 44 43 42 41 43 44 41 42 43 44 41 42 M61 and Rq 42 41 44 43 42 41 44 43 611 42 613 614 611 42 613 44 a Using Exercise 12 verify that i 4P P1P2P3P4 L4 ii P 4 P1P2P3P4 R4 b Conclude from part a that S5102 plap2p3p4 upRq c By direct computation verify that 4421 412 4 432 24142 24344 24143 24244 0 i 2 2 24142 24344 4421 412 42 43 24243 24144 0 MpRq 2 2 2 2 24143 24244 24243 24144 44 41 42 43 0 0 0 0 6112 61 61 614 d Conclude from parts 170 that if q qN then 2 2 2 2 44 41 42 43 24142 24344 24143 24244 2 2 2 2 R0tNa 24142 24344 44 41 42 43 24243 24144 2 2 2 2 24143 24244 24243 24144 44 41 42 43 14 Let q q40 q1iq2j q3k a By direct computation show that 2 2 2 2 1 414 44 41 42 43 24142 24344224143 24244 2 2 2 2 11 414 24142 24344a44 41 42 43224243 24144 2 2 2 2 111 4164 2611613 26126142612613 4611614614 41 42 43 d Conclude from part a that if q qN then 2 2 2 2 44 41 42 43 24142 24344 24143 24244 2 2 2 2 R0tNa 24142 24344 44 41 42 43 24243 24144 2 2 2 24143 24244 24243 24144 44 41 42 43 15 Show that a 4N 1 4N 4N 4N b rotN 1 r0tN T r0tN rot N 21 16 Let v be a vector and q be a unit quaternion Show that a b Sqv Sqv If Sqv rotates the vector v around the unit vector N by the angle 0 then Sqv rotates the vector v around the unit vector N by the angle 0 17 Let vw be unit vectors a Show that i v w is a unit quaternion ii vaw lies in the plane of the vectors vw iii v bisects the angle between w and SW w Prove that mirroring a vector u in the plane perpendicular to w and then mirroring the resulting vector in the plane perpendicular to v is equivalent to rotating the vector u around the vector v X w by twice the angle between w and v see also Exercise 21 18 In this exercise we will study the composite of two rotations a b c Using Lemma 1 showthat pqpq Conclude from part a that if p and q are unit quaternions then pq is a unit quaternion Using part b show that 61N1 i61N22 2 61N where i cos 2 cos 1 2cos 2 2 sin 1 2sin 2 2N1 39NZ ii sin 2N cos 2 2sin 1 2N1 cos 1 2 sin 2 2N2 sin 1 2 sin 2 2N1 X N2 Conclude from part c that 61N 19Na 2 61N 1 2 Using parts cd show that i rotN2 1 r0tN1 2 r0tN ii rotN 1 r0tN 2 rotN 1 2 19 In this exercise we explore the effect of sandwiching on points in affine space a Show that for any quaternions q 6117 Sqa b Sqa Sqb Show that i SqNyg0 0 ii SN 0 0 iii lo 00 c 0 22 c Conclude from parts ab that if P is a point in affine space then 1 SqN Y P rotates the point P by the angle around the line L through the origin parallel to the vector N H H S N P is not the mirror image of P in the plane through the origin perpendicular to the unit normal vector N Give a geometric interpretation of S N P iii S 0P scales the mass of P by the factor c but leaves the location of P unchanged 20 In this exercise we will develop formulas for some non conformal affine transformations see Lecture 12 using quaternions a Show that vNNv 1 N 39 v0 2 ii Ngtltv NVVN b Using the results of part a verify that i Orthogonal Projection onto the plane perpendicular to the unit normal N v SN v vnew T ii Parallel Projection onto the plane perpendicular to the unit normal N in the direction parallel to w v N w N v w Vnew V wNNw iii NonUniform Scaling along the direction w by the scale factor c v Swv c v Swv v new 2 2 21 In this exercise we will show that every rotation is the composite of two re ections Let N be a unit vector and let uv be two unit vectors in the plane perpendicular to N with sgnuvN gt 0 and 4u v 2 Show that a qN v u b SqNY w vu w uv c SqNY SV 0S d Conclude from part c that every rotation is the composite of two reflections 23 Lecture 3 Some Strange Properties of Fractal Curves I have been a stranger in a strange land Exodus 222 1 Fractal Strangeness Fractals have a look and feel that is very different from ordinary curves Unlike commonplace curves such as lines or circles there are no simple formulas for representing fractals like the Sierpinski gasket or the Koch curve Therefore it should not be surprising that fractal curves also have geometric features that are unlike the properties of any other curves you have previously encountered In this lecture we are going to explore some of the strangest peculiarities of fractals including their dimension differentiability and attraction 2 Dimension You may have been wondering about the origin of the term fractal Many fractal curves have a nonintegral dimension a fractional dimension somewhere between one and two Fractal refers to this fractional dimension Standard curves like the line and the circle are 1dimensional To say that a curve is 1 dimensional means that the curve has no thickness if the curve is black and the background is white then when we look at the curve we see white on either side of a thin black band see Figure 1 But fractals are different Look at the Sierpinski gasket or the C curve in Figure 1 There seem to be regions that are neither black nor white but instead are gray Such curves typically have dimension greater than one but less than two these curves do not completely fill up any region of the plane so they are not 2dimensional but neither are these gray curves as thin as idimensional curves To calculate the actual dimensions of fractal curves we first need to formalize the notion of dimension for some standard geometric shapes 31 g A 39quot39 53 2amp9 4 3 3 Figure 1 For the line and the circle there is a clear distinction between the curve black and the background white But for fractals like the Sierpinski gasket and the C curve the curve black and the background white interpenetrate and there are gray regions where the distinction between the curve and the background does not appear so clearly defined The dimension of a line segment is one the dimension of a square is two and the dimension of a cube is three There is a formal way to capture these dimensions Suppose we split these objects by inserting new vertices at the centroids of their edges and faces Then the line segment splits into 2 line segments the square into 4 22 squares and the cube into 8 23 cubes see Figure 2 In each case the dimension appears in the exponent There is nothing magical about splitting each edge into two equal parts If we split each edge into N equal parts then the line segment splits intoN line segments the square into N 2 squares and the cube into N 3 cubes Once again the dimension appears in the exponent Another name for an exponent is a logarithm so we are going to formalize the notion of dimension in terms of logarithms Figure 2 Inserting vertices at the centroids splits a line segment into 2 line segments a square into 4 22 squares and a cube into 8 23 cubes Another way of thinking about what we have just done is that we have split the line the square and the cube into identical parts where each part is a scaled down version of the original This decomposition should remind you of the fractals that you encountered in Lecture 2 where each fractal is composed of several identical scaled down copies of the original fractal Evidently in this construction for the line the square and the cube if N is the number of line segments along each edge and E is the number of equal scaled down parts then if D denotes dimension E ND L0gE 1 L0gN But if N is the number of line segments along each edge then S 1 N is the scaling along each DL08NE edge Since 05709 L0gN we can rewrite Equation 1 by setting L0gE D S 2 Log where S is the scale factor and E is the number of identical scaled down parts Equation 2 has several important properties First notice that S lt1 so 05708 lt 0 Therefore the minus sign on the right hand side of Equation 2 insures that the dimension D is positive Second since D is defined as the ratio of two logarithms the base of the logarithm does 2 not matter dimension is the same in all bases Finally Equation 2 gives the same result as Equation 1 for the line the square and the cube since in these cases E ND and S l N so L0gE L0gND DLOgN D L0gS L0gl N L0gN Let s see now what happens when we apply Equation 2 to selfisimilar fractal curves 21 Fractal Dimension To apply our dimension formula we need to consider selfisimilar curves Recall that a curve is selfsimilar if the curve can be decomposed into a collection of identical curves each of which is a scaled version of the original curve Most of the fractal curves we encountered in Lecture 2 such as the Sierpinski gasket and the Koch curve are selfisimilar curves In fact selfisimilarity is what allows us to write simple recursive turtle programs to generate these shapes Let s look now at some examples Example 1 Sierpinski Gasket The Sierpinski gasket consists of three smaller Sierpinski gaskets where the length of each edge of the smaller gaskets is oneihalf the length of an edge of the original gasket see Figure 3 left Thus E 3and Sl2so L0gE L0g3 L0g3 al585lltDlt2 L0gS L0gl2 L0g2 Example 2 Koch Curve The Koch curve consists of four smaller Koch curves each oneithird the size of the original curve see Figure 3 right Thus E 4 and Sl3 so LogltEgt Loglt4gt Loglt4gt al262lltDlt2 Logltsgt 39 Logo3 39 Logo w J 3 a m quotL 3 2i m wquot 4 Figure 3 The Sierpinski gasket left and the Koch curve right The Sierpinski gasket is composed of three selfisimilar parts the length of each edge of one of the smaller gaskets is one half the length of an edge of the original gasket The Koch curve is composed of four selfisimilar parts each oneithird the size of the original Koch curve 3 22 Computing Fractal Dimension from Recursive Turtle Programs The fractal dimension of a self similar fractal curve can often be computed directly from its recursive turtle program the number of recursive calls corresponds to the number E of equal self similar parts and the scale factor in the RESIZE command corresponds to the scale factor S Thus LogRecursiveCalls 3 LogScaleFactor I This formula like Equation 2 is valid provided that the self similar parts do not overlap To illustrate the validity of this formula let s revisit the fractal dimension of the Sierpinski gasket and Fractal Dimension the Koch curve Example 3 Sierpinski Gasket Recall from Lecture 2 that in the recursive turtle program for the Sierpinski gasket RecursiveCalls 3 and ScaleF actor 12 so LogRecursiveCalls Log3 Log3 LogScaleFactor Log12 Log2 39 Fractal Dimension Example 4 Koch Curve Again recall from Lecture 2 that in the recursive turtle program for the Koch curve Recursive Calls 4 and ScaleF actor 1 3 so Log Recursive Calls L0g4 ng4 LogScaleFactor Log1 3 Log3 39 Fractal Dimension Equations 2 and 3 may appear somewhat artificial and even contrived since these formula apply only to self similar curves but even many familiar shapes such as circles and ellipses are not self similar curves The notion of dimension can be defined for these curves as well but the mathematics required is way beyond the scope of this text The general notion of dimension is quite deep we shall not pursue this topic any further here 3 Differentiability A curve is said to be smooth or di erentiable if the curve has a well defined slope or equivalently a well defined tangent at every point Lines and circles are smooth curves Polygons and stars are piecewise smooth curves polygons and stars have well defined slopes everywhere except at their vertices The functions you studied in calculus polynomials trigonometric functions exponentials and logarithms are all differentiable functions What about fractals Differentiable functions are continuous everywhere but continuous functions need not be differentiable everywhere The function y x represents a continuous curve composed of two 4 lines the line y 71 for r 0 and the line y 1 for r 20 see Figure 4 Thus y le has slope 71 for i lt0 and slope 1 for 1 gt0 hutthe slope of y lx l is notwell de nedatthe origin A curve is srid to be piecewise linear if like the function y lx i it is composed of a sequence of straight lines 39 39 39 39 39 39 39 Thus it Figure 4 The graph of y e l r l When i is ne ptive the slope is 1 when r ispositive slopeis 1 Intuitively it seems evident that a continuous curve can have only a nite number of oints where the slope is not well de n ut intuition can be misleading Many fractal curves are Camimom everywhere but differenlmbze nowhere Consider the level eroi a on hllin point Level one however is a piecewise linear curve and there are three points where the slope is not defined Similarly at level two there are 15 points where the slope is not de ned At level n there are 4quot 1 points In fact in the limit the slope of the Koch curve is undefined at every point We mu n m 1m m is 1 Then the length of the line segments in level one is 13 the length of the line segrrrents in level two is 19 and in general the length of the line segments at levelnis 3 quot Thus the lengths Now he curve is the lengths of the line segments approach zero Thus in the limit the Koch curve is continuous everywhere but 39 39 391quotth 39 39 po 5 The Koch curve is not an anomaly In fact much the same arguments can be used to show that Virtually any bump fractal is continuous everywhere and differentiable nowhere Fractals are indeed very strange curves A m if mm m c Figure 5 Levels 0 1 2 3 of the Koch curve Level zero is a straight line which is smooth at every point Level one has three points where the slope is not defined level two has 15 points where the slope is not defined and level 3 has 63 points where the slope is not defined Notice too that the lengths of the line segments decrease from level to level by a factor of 3 4 Attraction How precisely does the fractal generated by a recursive turtle program depend on the choice of the base case Intuitively you might think that changing the base case will alter the fractal in some fundamental way But as we have just seen when we investigated differentiability our intuition regarding fractals can often be misleading We shall begin then by considering two familiar examples the Sierpinski gasket and the Koch curve Based on our experience with these two fractals we shall draw some highly counterintuitive and rather remarkable conclusions 41 Base Cases for the Sierpinski Gasket In the base case the standard program for the Sierpinski gasket draws a triangle see Lecture 2 The curves generated by levels 0136 of this program are illustrated in Figure 6 In Figures 7 9 we have changed the base case to draw a square a star and a horizontal line but we have not altered the recursive body of the program Each of these programs generates curves that start out quite different at levels 01 but by level 6 they all seem to be converging to the same Sierpinski gasket 42 Base Cases for the Koch Curve Let s try another example the Koch curve In the base case the standard program draws a straight line The curves generated by levels 0125 of this program are illustrated in Figure 10 In Figures 11 13 we have changed the base case to draw a square bump a square and a square where the turtle repeats the first side after completing her path around the square but we have not altered the recursive body of the program Again each of the curves generated by these programs starts out quite different at levels 01 but except for the program where the base case is a square see Figure 12 we will return to a discussion of this anomalous case shortly below by level 5 they all seem to be converging to the same Koch curve 6 AA A A AA A A A A STILAE 3 AC 3 k US 5 AA IAtI 7 AA AA 5 A k A A A A A AA k A L AA k AA k AA k A A k A AA U A A A A A A A A AfAAiAkj A k kAAihj A Ag A A kt AA A kt A AAAA kt kE Q A U A A A A k k Aq k A k A k k Ar A k AA Af k AA k AA 5 kA AA 9 k k kt At At K kAAI AAA A A At At A kAAA AAA Vt kt kC LAQ39 Aj39 Aj39 L AA k AA A k k LA Ab k Ld k Kc A9 A9 L k LAf k A A k A A A MWWMM mmma F 6 mm M LmM MdWM WMHmemmmmMm i mmmammwmwwmnmmmmmmm mmm mmmmmmmummmmmmm O Am a A 4 gt4 939 39 l 39 oo o 0 so 210 210 m W9 f 3 H a gm 21 A 3 J 39 mfm lm Figure 10 Levels 0 1 2 5 of the Koch curve The base case is a horizontal line g5 R 4 D U L Rwy m Figure 11 Levels 0 1 2 5 of the Koch curve The base case is a square bump o Figure 12 Levels 0 1 2 5 of the Koch program The base case is a square x 1 39 4 2 Figure 13 Levels 0 1 2 5 of the Koch curve The base case is a square where the turtle repeats the first side after completing her path around the square 43 Attractors When we first encountered recursive turtle programs our intuition lead us to believe that the precise form of the base case is critical for generating the desired fractal curve The natural base case for the Sierpinski gasket is a triangle the natural base case for the Koch curve either a straight line or a triangular bump But the examples we have just witnessed both for the Sierpinski gasket and for the Koch curve indicate that in the limit and as a practical matter after only about five or siX levels of recursion the base case is all but irrelevant Apparently a recursive turtle program will always converge to the same fractal curve independent of the turtle program in the base case When a process converges to the same limit value independent of the choice of the 8 initial value the limit value is called an attractor Fractals are attractors Figure 12 seems to challenge this conclusion here the expected convergence to the Koch curve fails to occur However the reason for this failure turns out to be that the recursion in the body of the turtle program for a bump fractal assumes that the turtle advances to the end of the line on which the bump occurs rather than return to her initial position This assumption is violated by the base case in Figure 12 but is satisfied by the base case in Figure 13 where the turtle repeats the first side of the square after completing her path around the square In future lectures we shall prove that in the limit as the number of levels approaches infinity the fractals generated by recursive turtle programs are indeed independent of the turtle program in the base case provided that the final state of the turtle in the base case is the same as the final state of the turtle in the recursion Usually as in the Sierpinski gasket the initial state and the final state of the turtle are identical but as illustrated by the Koch curve one must always be careful to check this assumption Thus with some mild assumptions the fractal generated in the limit by any recursive turtle program is indeed independent of the turtle program in the base case Fractals are attractors Indeed attraction is the signature property by which we recognize fractals But why does such a strange property hold To understand the reason behind this curious phenomenon we shall have to forgo for now our study of Turtle Graphics and investigate instead a very different approach to fractals called iterated mctions systems To understand iterated functions systems we shall first need to take up the study of affine transformations and affine graphics We shall commence with these topics in our next lecture 5 Summary From the turtle s point of view fractals are simply recursion made visible But from our perspective fractals generated from recursive turtle programs can have many strange properties 1 Fractals can be self similar fractals can often be decomposed into a collection of identical curves each of which is a scaled version of the original fractal curve Fractals can be continuous everywhere yet differentiable nowhere 3 Fractals can have fractional dimensions non integer dimensions between one and two 4 Fractals are attractors independent of the base case in the recursive turtle program that generates the fractal These four properties are characteristics of fractal curves that we do not find in common everyday curves together these features are what set fractals apart from our ordinary experience of geometry Exercises 1 Let P denote the perimeter of the nth level of the Koch snow ake a Show that 4 1 Pn Pn1 4 n 10145 b Conclude that the perimeter of the Koch snow ake is infinite 2 Let A denote the area enclosed by the nth level of the Koch snow ake a Show that i A A0 3A019 492 42934 19 ii LimneooA 8 5A0 b Conclude from Exercise 1 and part a that the Koch snow ake has an infinite perimeter but encloses a nite area c Explain why it is not possible for a curve to have a finite perimeter but to enclose an in nite area 3 Show that the bump fractals corresponding to the bump curves in Lecture 2 Figure 13 are continuous everywhere but differentiable nowhere 4 Consider the following recursive turtle program SQUARE Level IF Level 2 0 POLY 1 Jr 2 OTHERWISE REPEAT 4 TIMES RESIZE 12 SQUARE Level 1 RESIZE 2 MOVE 1 TURN Jr 2 a Show that as the level approaches in nity this program generates a filled in square b Compute the dimension of the square from this recursive turtle program 5 Compute the fractal dimension of the C curve 10 6 Compute the fractal dimension of the gaskets in Lecture 2 Figure 8 7 Compute the fractal dimension for each of the curves in Lecture 2 Figure 11 8 Compute the fractal dimension for each of the bump fractals corresponding to the bump curves in Lecture 2 Figure 13 9 Generate a fractal pentagonal gasket using the same recursive turtle program With three different turtle programs in the base case 10 Generate the fractal C curve using the same recursive turtle program with three different turtle programs in the base case 11 Generate the fractal tree in Lecture 2 Figure 11 using the same recursive turtle program with three different turtle programs in the base case Lecture 21 Shading put your trust in my shadow Judges 9 15 1 Polygonal Models Polygonal models are one of the most common representations for geometry in Computer Graphics Polygonal models are popular because the underlying surface of each polygon is a plane and planes are the easiest surfaces to analyze the normal vector along a plane is constant and the points on a plane satisfy a linear equation Thus rendering algorithms are particularly simple for polygonal models But models consisting solely of polygons also have severe limitations because planar polygons cannot model smooth curved surfaces To overcome this deficiency many small polygons are needed to simulate curved shapes But even with lots of small polygons the human eye is adept at seeing the edges between adjacent polygons Thus surfaces modeled by polygons do not look smooth The purpose ofshading algorithms is to smooth the appearance ofpolygonal models by reducing the impact of sharp edges in order to give the eye the impression of a smooth curved surface We shall study three different shading algorithms uniform shading Gouraud shading and Phong shading As in ray tracing we will consider three illumination models ambient reflection diffuse re ection and specular reflection Since a computer model of a complicated curved shape may contain millions of polygons the emphasis in shading algorithms is on speed A good shading algorithm must be fast and make the model look smooth shading algorithms are not necessarily intended to be physically accurate models of the behavior of light Uniform shading is fast but makes no attempt to smooth the appearance of the model Thus we introduce uniform shading only to compare the results with Gouraud and Phong shading Gouraud shading smooths the appearance of the model by linearly interpolating intensities along scan lines Phong shading simulates curved surfaces by linearly interpolating normal vectors along scan lines To speed up our computations we shall make several simplifying assumptions In addition to assuming that curved surfaces are approximated by planar polygons we shall assume that all light sources are point light sources and that both the light sources and the eye are located far from the model essentially at infinity These assumptions mean that the vectors to each of the light sources as well as the vector to the eye are constant along each polygon Together with the fact that the normal vector is constant along a polygon these assumptions help to simplify the computation of diffuse and specular reflections 11 Newell s Formula for the Normal to a Polygon Intensity calculations require normal vectors Polygons are typically represented by their vertices so to calculate the intensity of light on a polygon we need to compute the normal vector from the vertices Newell s formula is a numerically robust way to compute the normal vector of a polygon from its vertices Naively we could compute the normal vector N to a polygon from its vertices P0P by selecting two adjacent edge vectors 1 Pi2 Pl and setting NPi1 P1XPi2 Ii1a since this cross product is perpendicular to the plane of the polygon The problem with this approach is that two of the vertices might be very close together so one of the edge vectors E1 I iPl2 Pi1 might be very short worse yet the three points Ely fin might be collinear or almost collinear In each of these cases the computation of the unit normal N N is numerically unstable Newell s formula overcomes this difficulty by using all of the vertices to calculate the normal to the polygon For a derivation of Newell s forrnula see Lecture 11 Section 422 Newell 3 Formula II NkE PkXPk1 Pn1P0 11 0 Recall from Lecture 11 that the magnitude of the normal vector in Newell s formula is related to the area of the associated polygon In fact I N 2 X AreaP0lyg0n Thus Newell s forrnula avoids degeneracies due to collinear ver tices 2 Uniform Shading In uniform shading or at shading no attempt is made to smooth the appearance of a polygonal model Each individual polygon is displayed using the intensity formula uniform aka kadL39N1pksR39Vn 21 ammem di use specular where 0 N is the unit vector normal to the polygon L is the unit vector pointing from the polygon to the light source 0 V is the unit vector pointing from the polygon to the eye 0 R 2L39 N N L is the direction of the light vector L after it bounces off the polygon 2 By assumption the vectors N LRV are constant along each polygon so the intensity uniform is also constant along each polygon see Figure 1 For multiple light sources we add the contributions of the individual light sources Thus uniform shading is fast since we need to compute only one intensity for each polygon Unfortunately with uniform shading individual polygons are highly visible because the vectors NLRV and hence the intensity umform is different for each polygon Therefore discontinuities in intensity appear along the edges of the polygons and these discontinuities are heightened by the physiology of the eye Discontinuities in intensity along polygon edges are called Mach bands The purpose of the shading algorithms that we shall study next is to eliminate these Mach bands L N R Surface Figure 1 The vectors N LRV are constant along each polygon 3 Gouraud Shading The purpose of Gouraud shading is to eliminate Mach bands the method employed by Gouraud shading is linear interpolation of intensities The underlying strategy here for each polygon is to compute the intensities for the pixels in three steps i First calculate the intensities at the individual vertices of the polygon ii Next interpolate these vertex intensities along the edges of the polygon iii Finally interpolate these edge intensities along scan lines to the pixels in the interior of the polygon see Figure 2 We shall now elaborate on each of these steps in turn To compute the intensity at a vertex we need to know the unit normal vector at the vertex Since each vertex may belong to many polygons we first use Newell s formula Equation 11 to calculate the unit normal for each polygon containing the vertex We then calculate the unit normal vector at the vertex by averaging the unit normals of all the polygons containing the vertex 2 vertexE Polygon N polygon Nverlex 31 vertexE Polygon N JOIngl Finally we apply Equation 21 to compute the intensity at the vertex 3 Vertex Edge Edge Scan Line Vertex Vertex Scan Lme Edge Scan Line Edge Vertex Scan Line Edge Vertex Vertex Figure 2 Gouraud Shading First compute the intensity at each veItex Then interpolate these vertex intensities along each edge Finally interpolate these edge intensities to the pixels in the interior of the polygon by interpolating edge intensities along scan lines Once we have the intensities at the vertices we can apply linear interpolation to compute intensities first along edges and then along scan lines in the following fashion Suppose that we know the intensities 1112 at two points P1P2 The parametric equation of the line through P1P2 is t 1 tP1 th P1 tP2 P1 Linear interpolation means that we compute the intensity I at a parameter t by the analogous formula It 1 t11 t12 11 t12 11 To speed up the computation of intensity we shall reduce this computation to one addition per pixel by computing It incrementally For the line t At P1t AtP2 P1 P1 tP2 P1 AtP2 P1 Mt P1tP2 P1 so AL AtP2 P1 32 tAt LtAL Thus Lnexl Lourrenl AL 33 In terms of coordinates Equation 32 for AL is really three equations one for each coordinate Ax Atx2 x1 Ay Aty2 yl AZ Atzz zl 34 Similarly for intensity t At 11t At12 11 11 t12 11 At12 11 t 11 t12 11 AI M12 11 35 It At It AI Thus next current AI39 3396 Since we know 11 and 12 if we know At then we can compute AI and we can update next by a single addition per pixel Now consider what happens in two cases along a scan line and along an edge Along a scan line when we move to the next pixel Ax 1 see Figure 3 Since by Equation 34 Ax Atx2 x1 it follows that along a scan line At1x2 x1 AI 12 11At 12 11x2 x1 Ax 1 1 12 Pl x1vylvzl xyZ xAxyz P2 X2y222 Figure 3 Moving to the next pixel along a scan line Ax 1 To get to the next scan line we move along an edge When we move to the next scan line Ay 1 see Figure 4 Since by Equation 34 Ay Aty2 yl it follows that along an edge At 1012 Y1 AI 12 11At 12 11y2 yl Thus in each case we can reduce the computation of intensity to one addition per pixel 11 0 Pi X1gt 1gt11 xyz Ay 1 xy Ayaz 12 P2 X22Z2 Figure 4 Moving to the next scan line Ay 1 Notice that for adjacent polygons intensities necessarily agree along common edges because the intensities agree at common vertices Moreover on both sides of an edge the value of the intensity near the edge is close to the value of the intensity along the edge Thus linear interpolation of intensities along scan lines blurs the difference in intensities between adjacent polygons This blurring eliminates Mach bands and provides the appearance of smooth curved surfaces The Gouraud shading algorithm is an example of a scan line algorithm A scan line algorithm is an algorithm that evaluates values at pixels scan line by scan line taking advantage of the natural coordinate system induced by the orientation of the scan lines One problem that arises with a scan line approach to shading is that the method is coordinate dependent that is the intensities depend not only on the lighting but also on the orientation of the polygons relative to the coordinate system Consider for example the square in Figure 5 Oriented one way half the square is white whereas if the coordinate systems is rotated by 90 relative to the polygon the same half of the square is gray White Wk 8 White Not All White All White White White G ra y While Black Black Figure 5 The same square oriented differently relative to the coordinate system has different shading One way to fix this problem is to subdivide all the polygons into triangles Scan line algorithms for triangles are independent of the orientation of the triangles relative to the coordinate system We can establish this independence in the following manner Consider AP1P2P3 in Figure 6 Since P1P2P3 are not collinear the vectors P3 P1 P3 P2 span the plane Therefore any point P inside the triangle can be written uniquely as P P1 2P2 P133P3 P131P1 132P2133P3 where 31 32 33 1 The values 31132 33 are called the barycentric coordinates see Lecture 4 Exercise 24 of the point P We can compute the barycentric coordinates 31132133 by performing linear interpolation twice first along the edges of the triangle and then along a horizontal line see Figure 6 Using this approach we find that P 1 u1 t u1 sP11 utP2 Lag i z 3 But linear interpolations of intensities is performed in exactly the same way Thus I 1 u1 t u1 s11 1 ut12 213 3 1 l3 2 3 Since the barycentric coordinates 31 32 33 are unique this result is independent of the orientation of the triangle H 1 1 zP1tP2 1 9131ng 1 011 112 1 s11513 P2 12 P3 13 Figure 6 Linear interpolation for triangles for points along edges left and for intensities right Nevertheless even though for triangles the pixel intensities are independent of the orientation of the triangles relative to the coordinate system the pixel intensities for polygons still depend on exactly how we subdivide the polygons into triangles different subdivisions will generate different intensities for the same pixels 4 Phong Shading Gouraud shading reduces the visibility of polygonal edges by blurring the intensity across the boundaries of adjacent polygons But blurring these intensities also blurs specular reflections To reproduce sharp specular reflections we need a better way to simulate curved surfaces Phong shading simulates curved surfaces by interpolating normal vectors instead of intensities Normal vectors vary along a curved surface so Phong shading provides a better approximation to the intensity for curved surfaces modeled by planar polygons We begin by presenting a naive version of Phong shading more sophisticated enhancements will be presented in subsequent subsections 41 Naive Phong Shading The underlying strategy of Phong shading is similar to the underlying strategy for Gouraud shading except that intensities are replaced by normal vectors The normal vectors for each polygon are computed in three steps 7 i First calculate the normals at the individual vertices of the polygon Next interpolate these normals along the edges of the polygon H L iquot Finally interpolate these edge normals along scan lines to the pixels in the interior of the polygon Once the normal vectors are computed the intensities are calculated in the usual manner using Equation 21 As in Gouraud shading we calculate the unit normal vector at a vertex by Equation 31 averaging the unit normals of all the polygons to which the vertex belongs The unit normal for each polygon is computed by Newell s formula Equation 11 Once we have the unit normals at the vertices we can apply linear interpolation to compute normals first along edges and then along scan lines just as we calculated intensities for Gouraud shading If N1N2 are the unit normals at the end points P1P2 of the line Pt P1 tP2 P1 then using linear interpolation the normal N t at the point P t is calculated by Nt1 tN1tN2 N1 1N2 N1 To speed up the computation of normal vectors we reduce this computation to three additions one for each coordinate per pixel by computing normals incrementally using the same approach we used to compute intensities incrementally in Gouraud shading Replacing intensities by normals in Equation 35 leads to ANAKN2 N1 41 Nt At Nt AN Thus N next N current AN 42 Since we know N1 and N2 if we know At then we can compute AN and we can update N quotm by three additions one for each coordinate per pixel However to calculate intensities with Equation 21 we need not just a normal but a unit normal Thus after we calculate N next Nmrrem AN we need to renormalize that is we must calculate Num39l N current AN next I Nmmm AN I We compute the normals for Phong shading just like we computed the intensities for Gouraud shading in two stages along scan lines and along polygonal edges Recall that when we move to the next pixel along a scan line Ax 1 see Figure 3 Since by Equation 34 Ax Atx2 261 it follows that along scan lines At1x2 x1 AN N2 N1At N2 N1x2 x1 8 To get to the next scan line we move along an edge Now recall that when we move to the next scan line Ay 1 see Figure 4 Since by Equation 34 Ay Aty2 yl it follows that along edges At 1012 Y1 AN N2 N1At N2 N1 y1 Thus naive Phong shading is very similar to Gouraud shading we simply replace intensities by normal vectors in our calculations along edges and along scan lines There are however two differences we must renormalize the normal vectors after the incremental computation and then we must use these renormalized normals in Equation 21 to recalculate the intensity at each pixel These additional computations make naive Phong shading considerably slower than Gouraud shading In the next three subsections we shall develop more sophisticated techniques to increase the speed of Phong shading Phong shading like Gouraud shading is coordinate dependent that is the normals depend not only on the polygons but also on the orientations of the polygons relative to the coordinate system Once again we can fix this problem by subdividing the polygons into triangles since scan line algorithms for triangle are independent of the orientation of the triangles relative to the coordinate system Nevertheless as with Gouraud shading the normal vectors and hence the pixel intensities for polygons will still depend on exactly how we subdivide the polygons into triangles different subdivisions will still generate different intensities for the same pixels 42 Fast Phong Shading and Diffuse Re ection Linear interpolation for scalars is faster and cheaper than linear interpolation for vectors For diffuse reflection we can reduce at least part of the computation for Phon g shading from a vector calculation to a scalar calculation Recall that the formula for diffuse re ection is Idmse kadL 39N For Phong shading the normal vector N is calculated by linear interpolation that is Nt1 tN1tN2 Thus the unit normal is given by 1 t N1 tNZ Nittil I 1 tN1 tN2 Substituting this formula for the unit normal into the formula for diffuse re ection yields 1 tL 39N1 tL 39NZ 1 Ik Muse 1 1 tN1tN2 Now we can consider the numerator and the denominator independently We begin with the numerator Let J t L 39 N t Then the numerator is Jt1 tL39N1tL39N21 tJ1tJZ 43 where J1 L 39 N1 and J2 L 39NZ Equation 43 for J t is just linear interpolation of the scalar valued function J t L 39 N t We can calculate this scalar valued function at each pixel in exactly the same way that we calculate the intensities for Gouraud shading first calculate J t L 39 N t at the vertices then interpolate along edges and finally interpolate along scan lines This computation is line for line the exact same computation as Gouraud shading simply apply the computation to the linear function J t instead of the intensity It Now consider the denominator Let Nt1 tN1tN2 Then the denominator is given by dt Nt W From naive Phong shading Equation 41 we know that AN AtN2 N1 Therefore by Equation 42 Nnexl Nourrenl AN hence dnexl N next 39Nnexl 44 We can calculate AN and N next quickly using the scan line approach to linear interpolation presented in Section 41 what slows us down here is the square root in Equation 44 To find dnexl quickly we can apply Newton s method see Lecture 7 Section 31 to calculate this square root Let 2 2 2 F05 x dnexl x Nnexl Nnexl Newton s method starts with an initial guess x0 for a root of F x the value of dnexl and computes subsequent guesses xn1 from previous guesses x by the formula F0571 x 35 diexl F x 226 Since N changes only by a small amount from pixel to pixel AN is typically small so we can start xn1 xn the iteration with the initial guess x0 dwrrem Because our initial guess is already close to dnexl Newton s method will typically converge to a good approximation to the required square root after only a few iterations Notice that in this implementation we need to compute both N and d for each pixel The scan line algorithm is used to update N and d2 N 39 N Newton s method is used only to compute d de 43 Fast Phong Shading and Specular Re ection Recall that the formula for specular re ection is specular kasR 39 V where R 2L 39 N N L Substituting this expression for R into the formula for specular re ection yields Ispemm kas2L NN V L V 45 Now recall again that for Phong shading the normal vector N is calculated by linear interpolation so Nt1 tN1tN2 and 1 1 N1 tNZ Nunil t I 1 tN1 tN2 Substituting this formula for the unit normal into Equation 45 for specular re ection yields 7 21 tL39 N1 tL39 N21 tV N1 tV N2 L V 4 6 p tN1tN22 specular kas To analyze this formula let Jt L39 N t and K t V 39N t Then the first term in the numerator on the right hand side of Equation 46 is the product of the expressions Jt 1 tL39N1 tL39 N2 1 tJ1 tJZ Kt 1 tV 39N1 tV 39N21 tK1 tKZ where J1 L39 N1 J2 L 39NZ K1V 39N1 and K2 V39NZ These expressions are just linear interpolation for the scalar valued functions Jt L39 N t and K t V 39N I Once again we can calculate these scalar valued functions at each pixel in exactly the same way that we calculate the intensities for Gouraud shading first calculate Jt and K t at the vertices then interpolate along edges and finally interpolate along scan lines This computation is line for line the exact same computation as Gouraud shading with J t and K t in place of the intensity It Moreover the term L 39 V is a constant so we need to compute this value only once Thus we have 2amp1 tL39N1 1L39N21 tV39N1tV39N2 Similar to Gouraud Similar to Gouraud L39V H4 Constant I 1 1 k spew ar 17 SL 1 0N1 tNZIZ We are left to compute only the denominator of the first term on the right hand side This denominator is given by D0 Nt 2 Nt we Notice in particular that unlike the calculation of Phong shading for diffuse reflection there is no square root in this denominator Now from naive Phong shading Equation 41 we know that AN AtN2 N1 Therefore by Equation 42 Nnexl Nourrenl AN and Dnexl Nnexl 39Nnexl We can calculate AN and Nnexl quickly using the scan line approach to Phong shading presented in Section 41 and there is no square root here to slow us down as in the calculation of diffuse re ection to compute Dnexl from N next only one additional dot product is required 44 Phong Shading and Spherical Linear Interpolation In Phong shading we perform linear interpolation on unit normals But linear interpolation does not preserve length Therefore for every pixel we must renormalize the length of these normal vectors This renormalization takes time and involves a square root substantially slowing down the shading computation Linear interpolation is unnatural for unit vectors because linear interpolation does not preserve length But there is a natural way to preserve length while transitioning between two unit vectors we can simply rotate one vector into the other in the plane of the two vectors Rotation preserves length so no renormalization is required If we rotate at a uniform speed this approach is exactly spherical linear interpolation or slerp For a derivation of the formula for spherical linear interpolation see Lecture 11 Section 6 Spherical Linear Interpolation I l t I t slerpN1N2 t M1 Sln N2 s1n s1n 47 where cos 1N1 39 N2 Spherical linear interpolation eliminates the need to compute square roots renormalization but at the cost of computing the trigonometric functions sin1 t and sint This tradeoff hardly seems worthwhile Fortunately we can compute these trigonometric functions incrementally and thus avoid computing sines for every pixel To see how to compute the unit normal incrementally suppose we have already computed sin 1 t sin t g gt gtNl MN Sln s1n and we want to compute N t 48 sin 1 t At sin tAt Nt At W Ni NJ 7V s1n S1I1 First notice that the denominator sin is a constant Moreover since N1 N 2 are unit vectors cos N1 39N2 sin 1 cos2 quot1 N1 N22 The square root here is not a problem since this square root is computed only once We do not need to repeat this computation for each pixel rather we compute sin once and store the result Next observe that by the trigonometric identities for the sine of the sum or difference of two angles sint At sint cosAt cost sinAt 49 sin1 t At sin1 t cosAt cos1 t sinAt 410 Since At are constants the values cosAt sinAt are also constants so we can also compute these values once and store them for subsequent use Furthermore we can assume that we have already calculated sint sin1 t for the current pixel so we do not need to recalculate these values for the next pixel But we still need cost cos1 t Fortunately these values can also be computed incrementally from the trigonometric identities for the cosine of the sum or difference of two angles cost At cost cosAt sint sinAt 411 cos1 t At cos1 t cosAt sin1 t sinAt 412 Using equations 49 4 12 after computing the constants cosAt sinAt we can compute all the necessary sines and cosines incrementally with just four additionssubtractions and eight multiplications No trigonometric evaluations are necessary nor are any square roots required Now we can proceed in the usual fashion for Phong shading i First calculate the unit normals at the individual vertices of each polygon i Next apply spherical linear interpolation using equations 49 4 12 with 1 At 1 yz yl to calculate the unit normals incrementally along the edges of each polygon iquot Next apply spherical linear interpolation to the unit normals along the edges using equations 49 4 12 with At 1 x2 261 to calculate the unit normals incrementally along scan lines for the pixels in the interior of each polygon iv Finally use these unit normals to calculate the intensity at each pixel using Equation 21 13 The preceding algorithm corresponds to naive Phong shading with spherical linear interpolation replacing standard linear interpolation This procedure eliminates square roots but if we were to follow this approach in step iv we would need to compute two dot products L39 N and V 39 N for every pixel To eliminate these dot products we can proceed as in fast Phong shading by setting Jt L39 N t and K t V 39N t Substituting the right hand side of Equation 48 for N t into these expression for J t and K t yields the scalar valued functions Jo Sm1t L 39N S T Wh N2 s1n S1I1 Kt Sm1t V N1 Slum V N2 Sln Sln Now we can proceed as in the previous algorithm but instead of updating the unit normal vector Nt incrementally along scan lines using Equations 49 412 we use these equations to incrementally update the scalar valued functions Jt and K I along scan lines This approach eliminates the need to compute two dot products at every pixel but notice that we still need to update the normal vector N t incrementally along each edge since we need the angle between normal vectors at opposite edges along each scan line in order to calculate the functions J t and K I along the scan lines 5 Summary The purpose of shading algorithms is to smooth the appearance of polygonal models by reducing the impact of sharp edges in order to give the eye the impression of a smooth curved surface Gouraud shading blurs these sharp edges by applying linear interpolation to the intensity for each polygon along scan lines But Gouraud shading also blurs specular reflections Phong shading provides a better model for curved surfaces by performing linear interpolation of normal vectors along scan lines Phong shading is slower than Gouraud shading but Phong shading is considerably better for specular reflections We investigated several ways to speed up Phong shading including calculating diffuse and specular reflections independently by linear interpolation and using Newton s method to compute the square root needed to find the magnitude of the normal vector for diffuse reflection We also examined spherical linear interpolation of unit normals in order to avoid the square root altogether To speed up these algorithms the interpolation steps in both Gouraud and Phong shading are performed incrementally Below we summarize these incremental formulas for both Gouraud and Phong shading Gouraud Shading next current AI AI12 11X2 X1 M1211 Y2Y1 Phong Shading a Naive Phong Shading Nnexl I Nourrenl AN Nourrenl ANN2 N1X2 X1 ANN2N1 Y2 Y1 b F ast Phong Shading i ii DiffuseRe ection Jt L39Nt Jnexl errem AJ AJJ2 J1x2 x1 quot AJ J2 11 Y2 Y1 dnexl N next 39Nnexl Nnexl Nourrenl AN ANN2 N1x2 x1 quot ANN2 Nl Y2 Y1 Specular Re ection Jt L39Nt Kt V39Nt Jnexl errem AJ AJJ2 J1x2 x1 quot AJ J2 11 Y2 Y1 Knexl current AK AK K2 K1x2 x1 quot AK K2 K1 Y2 Y1 Dnexl Nnexl 39Nnexl Nnexl Nourrenl AN ANN2 N1x2 x1 quot ANN2 Nl Y2 Y1 intensity along scan lines along edges unit normal along scan lines along edges numerator along scan lines along edges denominator along scan lines along edges numerator along scan lines along edges along scan lines along edges denominator along scan lines along edges 15 c Spherical Linear Interpolation sin1 t At sint At N1 s1n s1n sin1 t At I sint At I Nnexz N0 N N2 along edges only 1m Jt At Sim N1 Sim N2 sin1 t At sint At Km Kt At Sim N1 Sim N2 sin I AIM sint cosAt cost sinAt sin 1 t AIM sin1 t cosAt cos1 t sinAt t At cost cosAt sint sinAt 1 t At cos1 t cosAt sin1 t sinAt At 1x2 261 along scan lines At1y2 yl along edges COS COS Exercises 1 A table of sines states that sin240 040674 and sin250 042262 Use linear interpolation to estimate sin2430 2 Show how to compute el incrementally using only one multiplication per pixel Programming Project 1 Implement both Gouraud and Phong shading in your favorite programming language using your favorite API a Use your implementation to shade several large polygonal models b Compare the relative speeds of the following algorithms for each of your models i Gouraud Shading ii Naive Phong Shading iii Fast Phong Shading iv Phong Shading using Spherical Linear Interpolation Lecture 20 Solid Modeling a cubit 0n the one side and a cubit 0n the other side Exodus 26 13 1 Solids A solid is a 3dimensional shape with two welldefined sides an inside and an outside Thus for any point in space it is possible at least in principle to determine whether the point lies on the inside or on the outside or on the boundary of a solid Solid modeling allows us to represent more complicated shapes than surface modeling With solid models we can compute mass properties such as volume and moments of inertia we can check for interference and detect collisions we can also apply finite element analysis to calculate stress and strain for solid models Three types of solid modeling techniques are common in Computer Graphics constructive solid geometry CSG boundary representations BRep and octrees Constructive solid geometry relies heavily on ray tracing both for rendering and for analysis so constructive solid geometry is closest to methods with which we are already familiar from surface modeling Boundary representations often rely on parametric patches such as Bezier patches or Bsplines freeform surfaces which we shall study later in this course In contrast octrees are an efficient spatial enumeration technique a method for approximating smooth 3dimensional shapes with a simple compact collection of rectangular boxes In this lecture we shall give a brief survey of each of these solid modeling methods and we shall compare and contrast the advantages and disadvantages of each approach 2 Constructive Solid Geometry CSG In constructive solid geometry we begin with a small collection of simple primitive solids boxes spheres cylinders cones and tori see Figure 1 and we build up more complicated solids by applying boolean operations union intersection and difference see Figures 2 and 3 to these primitive solids For example if we want to drill some holes in a block then we can model this solid by subtracting a few cylinders from a box see Figure 3 Figure 1 Primitives for a solid modeling system a box a sphere a cylinder a cone and a torus Solids are stored in binary trees called CSG trees The leaves of a CSG tree store primitive solids the interior nodes store either boolean operations or nonsingular transformations Nodes storing boolean operations have two children nodes storing transformations have only one child Boolean operations allow us to build up more complicated solids from primitive solids Transformations allow us to reposition the solid from a canonical location to an arbitrary location or to rescale the solid from a symmetric shape to a more general shape Each node of a CSG tree defines a solid The solid defined by a leaf node is the primitive solid stored in the leaf The solids at interior nodes are defined recursively If the interior node stores a transformation then the solid corresponding to the node is the solid generated by applying the transformation in the node to the solid stored by the node s child If the interior node stores a boolean operation then the solid corresponding to the node is the solid generated by applying the boolean operation in the node to the solids stored in the node s two children The solid corresponding to the root of the tree is the solid represented by the CSG tree see Figures 2 and 3 rotation Lylinder U Sphere cylinder Figure 2 A spherical tank with two cylindrical pipes left modeled by a CSG tree consisting of the union of a sphere and two cylinders right cylinder 3 cylinder 2 b0 cylinder 1 Figure 3 A solid block with three cylindrical holes left modeled by a CSG tree that subtracts three cylinders from a box right Ray tracing can be applied to render solids represented by CSG trees However unlike ray tracing for surface models where only isolated intersection points are computed ray tracing for solid models proceeds by finding the parameter intervals for which each line lies inside the solid We need these parameter intervals for two reasons First even if a ray intersects a primitive solid in a leaf node there is no guarantee that this intersection point lies on the boundary of the solid represented by the CSG tree since we may in fact be subtracting this primitive from the solid Keeping track of parameter intervals inside the solid instead of merely the intersection points on the surfaces bounding primitive solids allows us to keep track of which intersection points actually lie on the boundary of the solid Second later on we plan to use these parameter intervals to help compute mass properties such as the volume of a solid Thus to ray trace a solid for each line from the eye through a pixel we first compute the parameter intervals along the line for which the ray lies inside the solid We then display the point corresponding to the parameter closest to the eye Finding these parameter intervals for the primitive solids is usually straightforward since these solids are typically chosen so that they are easy to ray trace To find these parameter intervals for interior nodes we must consider two cases If the node stores a transformation T then the parameter intervals for the node along the line L are the same as the parameter intervals for the line T1L and node s child if the node stores a boolean operation then the parameter intervals can be found by applying the boolean operation at the node to the parameter intervals for the node s two children Pseudocode for ray tracing a CSG tree is presented below Ray Tracing Algorithm for CSG Trees For each pixel Construct a line L from the eye through the pixel If the solid is a primitive compute all the intersections of the line with the primitive Otherwise if the solid is a CSG tree If the root stores a transformation T Recursively find all the intervals where the line T1L lies inside the root s child Otherwise if the root stores a boolean operation Recursively find all the intervals in which the line intersects the left and right subtrees Combine these intervals using the boolean operation at the root Display the closest intersection point Ray casting can also be applied to compute the volume of solids represented by CSG trees Instead of firing a ray from the eye through each pixel fire closely spaced parallel rays at the solid Each ray represents a solid beam with a small cross sectional area AA If we multiply the length of 3 each interval 1k inside the solid by AA and add the results then we get a good approximation to the volume of the solid Thus Volume z 2k Length1kAA Alternatively we can apply Monte Carlo methods to compute the volume of a solid represented by a CSG tree Monte Carlo methods are stochastic methods based on probabilistic techniques Enclose the solid inside a rectangular box If we select points at random uniformly distributed inside the box then some of the points will fall inside the solid and some of the points will fall outside the solid The probability of a point falling inside the solid is equal to the ratio of the volume of the solid to the volume of the box Thus Points inside Solid V0lumeS0lid Points Selected V0lumeBox P 39 tr 39 39d S lid V0lumeS0lid z w X V0lumeBox Pomts Selected Therefore to find the volume of a solid all we need is a test for determining if a point lies inside or outside the solid There are two ways to perform this inside outside test by ray casting or by analyzing the CSG tree recursively To apply ray casting observe that a point lies inside a solid if and only if an arbitrary ray emanating from the point intersects the solid an odd number of times otherwise the point lies outside the solid Now the same interval analysis we applied in the ray casting algorithm for rendering solids represented by CSG trees can be applied to determine the number of times a ray intersects a solid and hence too whether a point lies inside or outside a solid However for CSG trees built from simple primitives it is easier to determine whether a point lies inside or outside a solid by analyzing the CSG tree recursively To begin one can easily determine whether a point lies inside or outside simple primitives like boxes spheres cylinders and cones by using the appropriate distance formulas see Exercises 1 3 For example a point P lies inside a sphere if and only if the distance from the point P to the center C of the sphere is less than the radius R of the sphere that is if and only if P C 2ltR2 For a solid such as a torus defined by an implicit equation F xyz 0 if the gradient VF BF BxBF ByBF dz represents the outward pointing normal then a point P lies inside the solid if and only if F P lt 0 if the gradient VF represents the inward pointing normal then a point P lies inside the solid if and only if F P gt 0 see Exercise 4 Once we have an inside outside test for each of the primitives we can generate an inside outside test for each CSG tree recursively in the following fashion If the root stores a 4 transformation T then a point P lies inside the corresponding solid if and only if the point T1P lies inside the solid represented by the root s child If the root stores a boolean operation then to determine if a point P lies inside the corresponding solid first perform tests to detennine if the point P lies inside the solids represented by each of the root s two children and then apply the boolean operation at the root to the outcome of these two tests Pseudocode for this inside outside test on a CSG tree is presented below Algorithm for Determining if a Point P Lies Inside 0r Outside a Solid Represented by a CSG Tree If the solid is a primitive Use the appropriate distance formula or the implicit equation associated with the primitive to determine whether the point P lies on the inside or the outside of the primitive Otherwise if the solid is a CSG tree If the root stores a transformation T Recursiver determine if the point T1P lies inside or outside the root s child Otherwise if the root stores a boolean operation Recursively determine if the point lies inside or outside the root s two children There are three cases to consider Uni0n If P lies inside the child at either node then P lies inside the solid Intersection If P lies inside the children at both nodes then P lies inside the solid Difference A B If P lies inside the child at the left node A and outside the child at the right node B then P lies inside the solid Otherwise P lies outside the solid Constructive solid geometry based on CSG trees has many advantages The representation is compact the data structure is robust and the user interface based on boolean operations is simple and natural Transformation nodes in the CSG tree permit parameterized objects based on canonical positions or canonical shapes The analysis of CSG trees is also straightforward ray casting can be used for rendering calculating volume and testing whether points lie inside or outside a solid Nevertheless constructive solid geometry also has certain disadvantages There is no adjacency information in a CSG tree That is there is no information about which surfaces are next to a given surface But adjacency information is crucial in manufacturing especially for NC machining Also in a CSG model there is no direct access to the vertices and edges of the solid Thus it is difficult for a designer to select specific parts of an object as referents nor can a designer 5 tweak the model by adjusting the location of veItices and edges Worse yet it is hard to extract salient features of the solid such as holes and slots which are important for manufacturing Finally the CSG representation of a solid is not unique After subtracting a primitive there is nothing to prevent us from unioning the primitive back into the solid Thus it is difficult to determine if two CSG trees represent the same solid Therefore even though CSG representations are simple natural and robust other types of representations for solids have been developed to overcome some of the shortcomings of constructive solid geometry 3 Boundary Representations BRep A boundary representation for a solid stores the topology as well as the geometry of the solid Geometry models position size and orientation topology models adjacency and connectivity Constructive solid geometry models the geometry of a solid but the topology of a solid is not present in a CSG tree Therefore we shall concentrate our discussion here on topology which is the novel component of the boundary file representation Topology consists of veItices edges and faces along with pointers storing connectivity information describing which of these entities are either on or adjacent to other entities An edge joins two vertices a face is surrounded by one or more closed loops of edges Topological information is binary data a vertex V is either on the edge E or not on the edge E a face Fl is either adjacent to another face F2 or not adjacent to the face F2 Topology allows us to answer basic topological queries such as find all the edges adjacent to the edge E or list all the faces surrounding the face F This topological information is what is missing from CSG representations Topology does not store any information about the position size and orientation of the vertices edges or faces this numerical data is stored in the geometry The geometry of a solid consists of points curves and surfaces along with numerical data describing the position size and orientation of these entities for each point coordinates for each curve or surface data for generating implicit or parametric equations Geometry is not concerned with adjacency or connectivity this information is stored in the topology Topology and geometry are tied together by pointers veItices point to points edges to curves faces to surfaces The data structure that encompasses the geometry the topology and the pointers from the topology to the geometry is called a boundary le representation BRep of a solid The topology of a solid can be quite elaborate There are nine potential sets of pointers connecting veItices V edges E and faces F see Figure 4 Maintaining this complete data structure would be complicated and time consuming Typically fewer pointers are actually stored tradeoffs are made between the speed with which each topological query can be answered and the amount of space required to store the topology W V BE lt gtFj Figure 4 The nine potential sets of pointers for a topological data structure The wingededge data structure is a standard representation for topology which makes a reasonable compromise between time and space Most of the pointers in a winged edge data structure are stored with the edges For solids bounded by 2 dimensional manifolds each edge lies on two faces and each edge typically connects two vertices In the vvinged edge data structure edges are oriented and each edge points to 2 Vertices Previous P and Next N orientation 2 Faces Left L and Right R 4 Edges PRNR and PLNL In addition each vertex points to one edge that contains the vertex and each face points to one edge that lies on the face see Figure 5 Figure 5 The winged edge data structure With the vvinged edge topology we can answer all questions of the form Is A on or adjacent to B Typical queries are Find all the edges surrounding a face Find all the faces adjacent to a face Find all the vertices lying on a face Find all the edges passing through a vertex We leave it as a straightforward exercise to the readers to convince themselves that these queries can 7 all be answered quickly and easily from the data stored in the vvinged edge topology see Exercise 9 The main advantages of the vvinged edge topology are that in addition to supporting fast retrieval of topological information the vvinged edge data structure is of moderate size and is relatively easy to maintain during boolean operations One problem with the vvinged edge topology is that this data structure does not support faces with holes that is faces defined by one exterior loop and one or more interior loops To solve this problem auxiliary edges are typically added to the model in order to connect the inner loops to the outer loop These auxiliary edges have the same face on both sides see Figure 6 Face Figure 6 A face with a hole The face is surrounded by two loops left An auxiliary edge connects the two loops right Notice that the auxiliary edge has the same face on both sides Boundary file representations are more complicated than CSG trees so it is easy to make a mistake in the topology when updating a model during a boolean operation One way to check the consistency of the topology in the boundary file is to verify Euler s formula Euler s formula for solids bounded by 2 dimensional manifolds asserts that V EF H2C G 31 where V vertices E edges F faces H holes in faces C connected components and G holes in the solid genus For example for a cube V 8 E 12 F 6 H 0 C 1 and G 0 Therefore V EF H22C G If Euler s formula is not satisfied then there is a error in the model Moreover it is unlikely though possible that an invalid model will actually satisfy Euler s formula Therefore Euler s formula provides a robust check for the consistency of the topological model Topology plays no essential role in rendering Therefore ray tracing for solids represented by boundary files is essentially the same as ray tracing for surface models simply intersect each ray with each surface on the boundary of the solid and display the closest intersection point Volume for solids with boundary file representations can be computed in three different ways by ray casting by Monte Carlo methods and by the divergence theorem The ray casting method for boundary le representations is similar to the ray casting method for constructive solid geometry Fire closely spaced parallel rays at the solid but instead of using the CSG tree use the boundary file representation to determine the intervals 1k along each line that lies inside the solid by intersecting each line with the surfaces that bound the solid Each ray represents a solid beam with a small cross sectional area AA so if we multiply the length of each interval 1k inside the solid by AA and add the results then we get a good approximation to the volume of the solid Alternatively we can apply Monte Carlo methods to find the volume of a solid by enclosing the solid in a rectangular box If we select points at random uniformly distributed inside the box then the probability of a point falling inside the solid is equal to the ratio of the volume of the solid to the volume of the box We can use ray casting at a boundary file representation to determined if a point lies inside a solid a ray emanating from a point lies inside a solid if and only if the ray intersects the surfaces bounding the solid an odd number of times The divergence theorem provides a novel technique for computing the volume of a solid with a boundary file representation which is not available for solids represented by CSG trees If the solid is bounded by the surfaces S Sk with outward pointing normals N N k then by the divergence theorem 1 1 Volume 3 53 P 39NdS EkffSkP39NkdSk 32 where P x yz represents an arbitrary point on the bounding surfaces If the surfaces bounding the solid are sufficiently simple then we can compute these integrals analytically see Exercise 10 otherwise we can use quadrature methods to approximate these integrals Boolean operations unlike rendering or volume computations are much more difficult for boundary file representations than for solids represented by CSG trees because for boundary frle representations not only the geometry but also the topology must be updated Unlike constructive solid geometry where boolean operations are performed simply by updating a CSG tree in a boundary frle representation the curves and surfaces of the first solid must be intersected explicitly with the curves and surfaces of the second solid to form the new vertices edges and faces for the topology of the combined solid These intersection computations are much more difficult than ray surface intersections so boolean operations on boundary file representations are much more difficult than boolean operations on CSG representations Pseudocode for boolean operations on boundary file representations is presented below Boolean Onemtinns on Boundarv File Input Boundary frle representations of two solids AB 9 Algorithm Intersect each surface face of A with each surface face of B to form new curves edges on A and B Difficult Computations Intersect each new curve with existing edges on the old faces to form new vertices and edges on A and B Insert the new faces edges and vertices into the topology of A and B Update Topological Data Structures Combine the boundary topologies based on the particular boolean operation 3A U B BA BAMB U BB BBMA 3A D B BAlnB U BBMA 3A B BA BAmB U BBmA 3B A BAinBU BB BBmA While this pseudocode may seem straightforward the actual computations can be quite difficult Computing accurate surface surface intersections is hard maintaining correct boundary les is time consuming as well as susceptible to numerical errors because to speed up the computations the intersections are typically calculated using floating point arithmetic Many man years are generally required to code robust boolean operations on boundary file representations The main advantage of boundary file representations is that adjacency information is readily available This adjacency information is important for manufacturing operations such as NC machining Adjacency information also permits the designer to modify the model by tweaking vertices and edges and to extract important features for manufacturing such as holes and slots Moreover unlike CSG representations the boundary file representation is unique Thus it is possible to decide whether two solids are identical by comparing their boundary frle representations Finally we can verify the correctness of the topological model by checking Euler s formula The main disadvantage of the boundary file representation is that maintaining the topology requires maintaining a large and complicated data structure Therefore boolean operations on boundary file representations are slow and cumbersome to compute Moreover floating point inaccuracies can cause disagreements between geometry and topology tangencies are particularly hard to handle Hence it is difficult to maintain robust boundary frle representations for solids bounded by curved surfaces Thus even though boundary frle representations facilitate the solution of several important problems in design and manufacturing boundary files also introduce additional problems of their own Therefore next we shall investigate yet another much simpler type of representation for solids that has some advantages over boundary file representations 10 4 Octrees Octrees are an efficient spatial enumeration technique In naive spatial enumeration space is subdivided into a large collection of small disjoint cubes all of the same size and orientation usually with faces parallel to the coordinate planes and each solid is defined by a list of those cubes lying inside or on the boundary of the solid The accuracy of spatial enumeration for solids bounded by curved surfaces depends on the size of the cubes used in the spatial enumeration so there are tradeoffs between the accuracy of the model and the space necessary to store the model To save on storage octrees vary the size of the cubes so that lots of small cubes get coalesced into larger cubes Large cubes are used to model the interior of the solid while small cubes are used to model the boundary of the solid The cubes in an octree are called voxels In an octree representation of a solid the number of voxels is typically proportional to the surface area most of the subdivision of large cubes occurs to capture the boundary of the solid Octrees to model solids are generated by the following divide and conquer algorithm Figure 7 illustrates a 2 dimensional analogue of an octree a quadtree for the area enclosed by a planar curve Octree Algorithm Start with a large cube containing the solid The faces of the large cube should be oriented parallel to the coordinate planes Divide this large cube into 8 octants Label the cube in each octant as either E 2 empty F 2 full or P 2 partially full depending on whether the octant is outside inside or overlaps the boundary of the solid Recursively subdivide the P nodes until their descendents are labeled either E or F or a lowest level of resolution cutoff depth is reached Figure 7 A quadtree model for the area enclosed by a planar curve Notice that most of the subdivision of the large squares into smaller squares occurs along the bounding curve 1 1 Since an octree is just a collection of different size cubes many algorithms for analyzing solids represented by octrees reduce to simple algorithms for analyzing cubes For example to render an octree by ray tracing simply intersect each ray with all the F voxels and accept the nearest hit To nd the volume of an octree simply sum the volume of the F voxels Simple pseudocode for boolean operations on octrees is presented below Boolean Onemtinns for Octree Input Octree representations of two solids AB Algorithm Apply the boolean operation to corresponding nodes in the octree representations for AB There are three cases to consider Uni0n If either node is labeled F label the result with F Otherwise if both nodes are labeled E label the result with E Otherwise label the new node as P and recursively inspect the children Intersection If either node is labeled E label the result with E Otherwise if both nodes are labeled F label the result with F Otherwise label the node as P and recursively inspect the children Difference A B If the A node is labeled E or the B node is labeled F label the result with E Otherwise if the A node is label F and the B node is labeled E label the result with F Otherwise label the node as P and recursively inspect the children If all the children are labeled E F then change the label P to the label E F The main advantages of octree representations are that they are easy to generate and they are much more compact than naive spatial enumeration Moreover octree representations can achieve any desired accuracy simply by allowing smaller and smaller voxels Many analysis algorithms for octrees such as ray tracing volume computations and boolean operations reduce to simple algorithms for analyzing cubes Scaling along the coordinate axes and orthogonal rotations around coordinate axes are also easy to perform simply by scaling and rotating the voxels Finally octrees facilitate fast mesh generation for solids The main disadvantage of octree representations is that the voxels are usually aligned with the coordinate axes Thus most octree models are coordinate dependent Therefore it is difficult to perform an arbitrary affine transformation on an octree representation of a solid Also when highly accurate models are required octree representations will use lots of storage to model curved boundaries so for highly accurate models octree representations can be extremely inefficient 12 5 Summary There are three standard techniques in Computer Graphics for modeling solids CSG trees boundary files BRep and octrees Each of these representations have certain advantages and disadvantages For easy reference in Table 1 we compare and contrast six of the main properties of these three representations for solids including i the accuracy of the model ii the size of the domain of the solids that are readily represented by the model iii the uniqueness of the model iv the ease of verifying the validity of the model v Whether or not the model is closed under boolean operations and finally vi the compactness of the model m m Accuracy Good Good Mediocre Domain Large Small Large Uniqueness No Yes Yes Validity Easy Hard Easy Closure Yes No Yes C ompaclness Good Bad Mediocre Table 1 Comparison of different solid modeling methods Exercises 1 Consider a box with a corner at Q edges parallel to the unit vectors abc with length Width and height given by the scalars Lw h see Figure 8 Show that a point P lies inside the box if and only if the following three conditions are satisfied i 0ltP Q altl ii 0 ltP Q b ltw iii 0ltP Q c lth Interpret these formulas geometrically Cl h I Q rim 1 r Figure 8 A box With a corner corner at Q edges parallel to the unit vectors abc with length Width and height given by the scalars Lw h 13 2 Consider a bounded cylinder of radius R and heightHwith an axis line L determined by a base point Q and a unit direction Vector A see Figure 9 Show that a pointP lies inside the cylinder if and only if the following two conditions are satisfied i PQ PQPQ A2ltR2 ii P Q gAA H lt 2 Interpret these formulas geometrically A I L a g EE 4quot m a gggg u l r rf m g 5 5 ggga gga aggg I 5 4 Figure 9 A bounded cylinder of radius R and height H with an axis line L determined by a base point Q and a unit direction Vector A 3 Consider a bounded cone with Vertex V cone angle 0 height H and an axis line L parallel to a unit direction VectorA see Figure 10 Show that a point P lies inside the cone if and only if the following two conditions are satisfied i P V o A2 gtl P V l2 cos2o ii 0ltP V AltH Interpret these formulas geometrically V Figure 10 A bounded cone with Vertex V cone angle or and heightH with an axis line parallel to the unit direction Vector A 4 Consider the torus With center at the origin and axis parallel to the z axis With a generator of radius d and a tube radius 0 Recall from Lecture 19 Section 6 that this torus is described by the implicit equation 2 Fxyz E x2 y2 z2 d2 02 4d2z2 4a2d2 0 Show that 8F 8F 8F a VF 4xGxy z 4yGxyz 4zGxyz 2412 is the outward 8x 8y dz pointing normal Where Gxyz x2 y2 z2 d2 02 b A point P x yz lies inside this torus if and only if F P lt 0 5 Consider a torus With center C and axis parallel to the unit vector A With a generator of radius d and a tube radius a see Figure 11 Show that a point P lies inside this torus if and only if 2 P C A2 P CIZ P CA2 w lt02 Interpret this result geometrically Figure 11 A torus With center C and axis parallel to the unit vector A With a generator of radius d and a tube radius a 6 Verify Euler s formula for the cube the tetrahedron and the octahedron 7 Verify Euler s formula for a cube With a rectangular hole passing through the top face and ending at the center of the cube 8 Verify Euler s formula for a cube With a A rectangular hole from top to bottom b Two rectangular holes one from top to bottom and one from front to back c Three rectangular holes top to bottom front to back and side to side 15 9 Develop algorithms based on the vvinged edge topology to answer the following queries 10 Let T be a polyhedron bounded by planar polygonal faces Sk Let Qk be a fixed point on Sk and let Nk be the outward pointing unit vector normal to Sk Using the divergence theorem a b c d Find all the edges surrounding a face Find all the faces adjacent to a face Find all the vertices on a face Find all the edges passing through a vertex Equation 32 show that 11 Develop an efficient algorithm to detennine if a given point lies inside or outside of a solid 1 VolT 2kQk 39NkAreaSk represented by an octree Programming Projects 1 Constructive Solid Geometry Implement a solid modeler based on constructive solid geometry in your favorite programming language using your favorite API a Include the following primitive solids Boxes and Wedges Spheres Cylinders and Cones Tori b Incorporate the following boolean operations 0 Union Intersection Difference c Develop algorithms to render these solids d Develop algorithms to compute the volume of these solids Octrees Implement a solid modeler based on octrees in your favorite programming language using your favorite API a Incorporate the following boolean operations 0 Union Intersection Difference Develop algorithms to render these solids Develop algorithms to compute the volume of these solids 1 6 Lecture 19 Surfaces II Simnle Surfaces He hath put down the mighty from their seats and exalted them aflow degree Luke 152 1 Simple Surfaces Some surfaces are easy to describe without equations A sphere is the locus of points at a xed distance from a given point a cylinder is the locus of points at a fixed distance from a given line Thus a sphere can be represented simply by a center point and a radius a cylinder by an axis line and a radius For these simple surfaces we shall see that we can compute surface normals and ray surface intersections directly from their geometry without resorting to implicit or parametric equations Thus ray tracing these surfaces is particularly easy In this lecture we will investigate ray tracing strategies for surfaces defined geometrically rather than algebraically These surfaces include the plane and the natural quadrics the sphere the right circular cylinder and the right circular cone We shall also explore ray tracing for general quadric second degree surfaces as well as for the torus which is a surface of degree four General surfaces of revolution will also be investigated here These surfaces are among the simplest and most common surfaces in Computer Graphics so they deserve special attention 2 Intersection Strategies Special strategies exist for ray tracing simple surfaces One of the most common tactics is to apply a transformation to reduce the ray surface intersection problem to a simpler problem either by projecting to a lower dimension or by repositioning to a canonical location or by rescaling to a symmetric shape Consider intersecting a curve C and a surface S If a point P lies on the intersection of the curve C and the surface S then for any affine or projective transformation M the point P M lies on the intersection of the curve C M and the surface S M If the transformation M is cleverly chosen in many cases it is easier to intersect the curve C M with the surface S M rather than the original curve C with the original surface S Moreover if the transformation M is invertible then PEC S ltgt PMECM SM Therefore when M is invertible we can find the intersection points of the the original curve C and the original surface S by computing the intersection points of the transformed curve C M with the transformed surface SM and then mapping back by M1 This method is essentially the deformation technique discussed in the previous lecture though M may also be a rigid motion as well as a shear or a scale But what if the transformation M is not invertible For example what if M is an orthogonal or perspective projection Remarkably for parametric curves and surfaces the same strategy can still work Consider intersecting a parametric curve C Ct and a parametric surface S Su v The curve C and the surface S intersect whenever there are parameter values tu v for which Ct Suv Applying an affine or projective transformation M yields Ct M Suv M Thus if the original curve and surface intersect at the parameters tuv so will the transformed curve and surface The intersection points may change but the parameter values are unaffected This observation is the key to our intersection strategy If no new intersection points are introduced by applying the transformation M then we can find the intersection points of the original curve and surface by solving for the parameters t or uv of the intersection points of the transformed curve and surface and then substituting these parameter values back into the original parametric equations C C t or S S 14 v to find the intersection points of the original curve and surface Moreover even if we do introduce some new spurious intersection points by applying a singular transformation we never lose any of the old intersection points So at worst we would need to check whether the parameters representing intersection points on the transformed curve and surface also represent intersection points on the original curve and surface But we can always verify potential intersections by substituting the intersection parameters back into the parametric equations of the original curve and surface and checking whether or not we get the same point on the curve and the surface that is by verifying that C t Suv We shall see many examples of this general transformation strategy for computing intersections throughout this lecture 3 Planes and Polygons A plane can be described by a single point Q on the plane and a unit vector N normal to the plane A point P lies on the plane if and only if the vector P Q is perpendicular to the normal vectorN or equivalently if and only if N 39 P Q 0 A line Lt P tv intersects the plane determined by the point Q and the normal vectorN at the parameter value t where N39Lt Q NP tv Q0 2 If N 39 v 0 then the line is parallel to the plane so the line and plane do not intersect Otherwise solving for the parameter t yields N 39 P t Q I 31 39 v Substituting the parameter t back into the equation of the line we find the intersection point RLtPtv 32 Thus we have a simple algorithm to intersect a line with an in nite plane Often however we want to find the intersection of a line with a finite polygon rather than with an infinite plane For example when we ray trace a cube the faces of the cube are squares not infinite planes Even if a line intersects the plane containing the polygon the line might not intersect the plane at a point inside the polygon For convex polygons like triangles and rectangles there is a straightforward test for determining if a point R on a plane of the polygon lies inside the polygon Consider a closed convex polygon with vertices P i 1m 1 where Pm1 P1 Let Nil1 be the vector normal to the edge EPlH and pointing into the polygon see Figure 1 Figure 1 A pointR in the plane of a convex polygon lies inside the polygon if and only if R lies on the positive side of the inward pointing normal vector to each boundary line A pointR in the plane of the polygon lies inside the polygon if and only if Ni1i139R I20 i1m 33 To find the normal vectors Nil1 observe that if the vertices of the polygon are oriented counterclockwise with respect to the normal N to the plane of the polygon then Ni1i1NxPi1 Pi i1m and Equation 33 reduces to detN Pi1 PiR Pi20 i1m 34 if the vertices are oriented clockwise with respect to the normalN then Ni1i1Pi1 PigtltN i1m and Equation 33 reduces to detR Pl Pi1 IN20 i1m 35 The tests in Equations 33 35 work only for convex polygons For arbitrary possibly non convex planar polygons there are more general inside outside tests based either on ray casting or on winding numbers The details of these tests are provided in Lecture 11 Section 7 In most cases however we shall be interested only in convex polygons so we shall not generally require these more sophisticated tests 4 Natural Quadrics The natural quadrics consist of the sphere the right circular cylinder and the right circular cone These three second degree surfaces are among the most common surfaces in Computer Graphics so we shall develop special ray tracing algorithms for each of these surfaces Moreover for these three surfaces we shall reduce the ray surface intersection computation to a single algorithm for computing the intersection of a line and a circle 41 Spheres Next to planes spheres are the simplest and most common surfaces in Computer Graphics Therefore we would like to have a simple way to represent spheres as well as a fast robust ray sphere intersection algorithm A sphere S can be represented simply by a center point C and a scalar radius R The vector N from the center point C to a point P on the surface of the sphere S is normal to the surface of the sphere at the point P Therefore the outward pointing normal vectorN at the point P is given by Nsphere P C To simplify the ray sphere intersection calculation we shall reduce the 3 dimensional ray sphere intersection problem to a 2 dimensional ray circle intersection problem Suppose we want to intersect the line L with the sphere S Consider the plane containing the center point C and the line L see Figure 2 This plane intersects the sphere S in a circle with center C and radius R and the line L intersects this circle in the same points that the line L intersects the sphere 411 Intersecting a Line and a Circle To find the intersection points of a line and a circle we can take a simple geometric approach Let the line L be determined by a point P and a direction vector v First we check the distance from the center point C to the line L If this distance is greater than the radius R then there is no intersection between the line and the circle Thus we have a fast test for rejection Otherwise we proceed by first finding the point Q on the line L closest to the center point C We then use the Pythagorean theorem to calculate the distance from Q to the intersection points AB of the line and the circle Below is pseudocode for this Line Circle intersection algorithm Figure 2 A line determined by a point P and a vector v intersecting a circle with center C and radius R Line Circle Intersection Algorithm Input C 2 Circle Center R 2 Circle Radius P 2 Point on the Line v 2 Vector in the Direction of the Line Algorithm If Dist2C L gt R2 there are no intersection points fast reject Otherwise Normalize the direction vector v to a unit vector v gt L Iv Find the orthogonal projection w of the vector P C on the line vector v wP CJP C P C39vv Find the point Q on the line L closest to the center point C QCw Using the Pythagorean theorem find the distance x from the point Q to the intersection points AB x2 R2 w Compute the intersection points AB A Q x v B Q xv 412 Inversion Formulas for the Line The preceding algorithm finds the intersection points of a line and a circle or equivalently a line and a sphere But in ray tracing we also need to know the parameter values along the line corresponding to these intersection points A formula for finding the parameter value corresponding to a point along a line is called an inversion formula for the line The exact form of the inversion formula depends on the particular form of the parametric equation of the line Consider for example a line L determined by a point P and a vector v then Lt P tv If Q is a point on the line Lt then for some value t Q P tv Subtracting P from both sides dotting with v and solving for tyields Inversion Formula Linear Parametrization P I t M 4 1 v 39v When v is a unit vector then v 39v 1 and this inversion formula simplifies to Inversion Formula Linear Parametrization with Unit Vector v tQ P39v 42 If the line L is determined by two points P0 P1 rather than a point P and a vector v then Lt 1 tP0 tP1 P0 tP1 P0 Therefore to nd the parameter value corresponding to a point Q on the line Lt we can use the rst inversion formula Equation 41 with v P1 P0 Suppose however that L is the image under perspective projection of a line in 3 space Perspective projection maps points and vectors into mass points Therefore if the original line is represented either by a point and a vector or by two points then the image L is represented by two mass points X0m0 and X1m1 Here if mk 0 then Xk mkPk where Pk is a point in aff1ne space whereas if mk 0 then X k vk where vk is a vector In either case since L is determined by mass points to find the af ne points on the projected line Ptv gtX0m0 tX1m1 we must divide by the mass Thus L has a rational linear parametrization X 0 tX 1 m0 tml I Mt To find an inversion formula for a line Lt with a rational linear parametrization let Q be a 6 point on the line 03 Then for some value oft W Multiplying both sides by me tml yields mg tm1QX0 tX1 or equivalently moQ 7 X0 rltX1 r m1Q Dottin g both sides with X1 7 le and solving for t we arrive at Inversian Farmula Ratianal Linear Parametrizatian tmoQX039X1 m1QI 43 X1 rle 3906 rle If moym1 0 then Xkmk mkPkmk and this formula reduces to Inversion Formula Rational Linear Parametrization with m0m1 0 m0QP039P1 Q 44 t m1P1 Q39P1Q We shall have occasion to apply these inversion formulas for rational linear paiametrizations of the line in Section 43 when we ray tmcet e cone 42 Cylinders A sphere is the locus of poian equidismnt from a given point acylinder is the locus of points equidistant from a given line Thus a cylinder can be represented simply by an axis line L and a scalar radius R Typically the axis line L is itself represented by a point Q on the line and a unit direction vector A parallel to the line see Figure 3 ll 51 2 u gig gn Iggg w 5E w g s g E f 5 a 55r g g 5gg 4 gg N Figure 3 A right circular cylinder with an axis line L determined by a point Q and a unit direction vector A to the surface of the cylinder at the point P is the orthogonal component of the vector P 7 Q with respect to the axis vector A 7 The normal N to the cylinder at a point P on the surface is just the orthogonal component of the vector P Q with respect to the axis vector A see Figure 3 Therefore Ncylinder P QJ P P 39 AA 421 Intersecting a Line and an Infinite Cylinder As with the sphere we can reduce the ray cylinder intersection problem to a ray circle intersection problem The strategy here is to project both the cylinder and the line orthogonally onto the plane determined by the point Q and the axis vector A The cylinder projects to the circle with center Q and radius R the line projects to another line Now we can use the algorithm in the previous section to intersect the projected line with the circle However orthogonal projection is not an invertible map so we cannot use the inverse map to recover the actual intersection points of the line and the cylinder What saves us here is our observation in Section 2 that the parameters of the intersection points of the projected line and the projected cylinder the circle are the same as the parameters of the intersection points of the unprojected line and the unprojected cylinder Thus to intersect a line and a cylinder we can proceed in the following manner Let the line L be determined by a point P and a unit direction vector v If the distance from the cylinder axis to the line L is greater than the cylinder radius R or if the direction of the line vector v is parallel to the direction of the cylinder axis vectorA then there is no intersection between the line and the cylinder Thus once again we have fast tests for rejection If the line and the cylinder do intersect then we project the line L orthogonally into the plane determined by the point Q and the axis vectorA and we intersect the projected line with the projection of the cylinder the circle with center Q and radius R We then apply the inversion formula for the projected line to find the corresponding parameter values Finally we substitute these parameter values into the equation of the original line L to find the intersection points of the line and the cylinder Below is pseudocode for this Line Cylinder intersection algorithm Notice that this algorithm computes both the intersection points and the parameter values along the line corresponding to these intersection points Line Cylinder 39 Algorithm Infinite Cvlinder Input Q 2 Point on the Cylinder Axis A 2 Unit Direction Vector Parallel to the Cylinder Axis R 2 Cylinder Radius P 2 Point on the Line L v 2 Unit Vector in the Direction of the Line L Algorithm If DistAxis LineL gt R or V II A I v 39 A 1 there are no intersection points fast reject Otherwise Project the line L into the plane determined by the point Q and the axis vector A and nd the equation of the projected line L i LJt Pi tvi vi v v39AA Pi P P QAgtA Intersect the projected line L i with the circle with center Q and radius R Apply the line circle intersection algorithm in Section 411 to find the intersection points D1 D2 Use the inversion formula in Section 412 for the line L i t Pi tvi or alternatively apply Exercise 8 to find the corresponding parameter values t t1 t2 D PJ39vJ D P 39vi vi 39 vi v 39 vi Substitute the parameter values t t1 t2 into the equation of the line L to find the t1 iL2 intersection points R1R2 of the line and the cylinder RiLtlPtiv i12 422 Intersecting a Line and a Bounded Cylinder The preceding algorithm intersects a line with an infinite cylinder but most of the cylinders that appear in Computer Graphics are closed and bounded Thus additional computations are needed to find the intersections of the ray with the disks at the top and the bottom of the cylinder Fortunately these computations are easy to perform To intersect a line with a bounded cylinder first intersect the line with the planes of the two bounding disks then test to see whether or not these intersections points lie within a distance R of the centers of these disks If both intersection points lie inside the bounding disks then the line cannot intersect the surface of the bounded cylinder otherwise use the algorithm in the preceding section to find the intersection points of the line with the infinite cylinder and discard those intersection points that are not within the bounds of the finite cylinder Below is pseudocode for the Line Cylinder intersection algorithm for bounded cylinders Line Cvlinder 39 Algorithm Rounded Cvlinder Input Q 2 Point on the Cylinder Axis at the Base of the Cylinder A 2 Unit Direction Vector Parallel to the Cylinder Axis R 2 Cylinder Radius H 2 Cylinder Height P 2 Point on the Line L v 2 Unit Vector in the Direction of the Line L 9 Algorithm If the line L is parallel to the plane determined by the point Q and the unit normal vector A that is if v 39 A z 0 then If the distance from the line L to the plane determined by the point Q H 2A and the normal vector A is greater than H2 then there are no intersections between the line L and the bounded cylinder If P QH2AA gt H 2 then the line L does not intersect the cylinder Otherwise use the algorithm in Section 421 to intersect the line L with the infinite cylinder and store the results Otherwise intersect the line L with the planes of the two disks bounding the cylinder Use the results in Section 3 to find the intersection points E1 E2 of the line L and the two planes determined by the points Q and Q H A and the unit normal vector A If the distance of these intersection points E1 E2 from the centers Q Q H A of the corresponding disks are less than the radius of the cylinder then save these intersection points and stop Test Dmhg E1 lt R2 and Dist2Q HAE2 lt R2 Otherwise intersect the line E t E1 tE2 E1 with the infinite cylinder Use the algorithm in Section 421 for intersecting a line and an infinite cylinder to find the intersection points D1D2 and the corresponding parameter values t1 t2 Discard any intersection point D1 with parameter value t1 lt 0 or t gt 1 i 12 since intersections of the line L with the bounded cylinder must lie between E1 and E 2 Now there are two cases Case 1 Both points E1 E2 lie outside the corresponding disks Either both D1 and D2 lie on the bounded cylinder or the line L does not intersect the bounded cylinder Case 2 One of the points E1 or E2 lies inside the corresponding disk and the other point lies outside the corresponding disk Exactly one of the points D1 or D2 lies on the bounded cylinder and one of the points E1 or E2 lies on one of the bounding disks Notice that in both cases we need to test only one of the parameters t1 t2 to see if the parameter lies in the interval 01 Whether we will need to keep or discard the other parameter is completely determined by the case no further testing is required 43 Cones A cone can be represented simply by a vertex V a unit axis vector A and a cone angle a see Figure 4 Notice that a cylinder is a special case of a cone where the vertex V is located at infinity 10 m marmale m an A and acampamm mpamm slang m mm m pump 3 mg p x can mapmmpamh m s m snmaf am anngm vecmx piv run them mm vm o By stnlgh vml ngmmmeh y m lzngthafcampammafNaJnngAls 11mm v n Angm cucularcar Valhame v am am vecmxA and mrma vecme m m a h car a m m p can he dzca campanzms an almgthz msaflhz can and athzralnngthz v m pmmP Eymgmmmzh39y h lzngthafcampammafNaJnngAls w 7v Um u a car avg a m mpased mm sum at Ma cmx mu m mm mm vm yumquot we can mum m mycar mmm m a x mmm by e Dnvg1mmnm a pm mammzx we pelspecn e pmyeconn m m magnum has m 1m yam M e Seaman o 12 Nevenhz s anmw pmceed m e m m myrcy x mmm anthm mmsecnthmyec mm mththzcnclzm m mxvahlzscunespardug m m mmm palm and mum g me valvzs m 1 mm m squanan cm W m m mm mmm pm at max wnh n2 law pseudncadz in this algaan campnms mm m m man pm 31g thm autumnalqu 31mg m hm camspammg m mm mmseconn pm W by v Can Venex A 2 Unit Direction Vector Parallel to the Cone Axis x 2 Cone Angle P 2 Point on the Line L u 2 Unit Vector in the Direction of the Line L Algorithm Project the line L into the plane determined by the point Q V A and the normal vector A and find the rational parametrization of the projected line Lt X 0 tXl m0 tml X0 V Q39APQ P39AV PQ P39AV moV P 39AQ P A 1 Lt X1V Q39 Au u39AV u u39AV m1 u 39 A Intersect the projected line L with the circle with center Q V A and radius R Tanx Apply the line circle intersection algorithm to nd the intersection points D1D2 There are four cases to consider depending on the masses m0m1 Case 1 m0 m1 0 The line L projects to the line at in nity so there are no intersection pomts between the circle and the line L t Case 2 m0m1 0 The line L t is determined by the two affine points X X X X 0 1 or equivalently by the pomt P 0 and the vector v 0 1 m0 m1 m0 m0 m1 Case 3 m0 0 m1 0 The line Lt is determined by the affine point X P 0 and the vector v X1 m0 Case 4 m0 0 m1 0 The line Lt is determined by the affine point X P 1 and the vector v X0 m1 Use the inversion formula for the rational linear parametrization of the line Lt or alternatively apply Exercise 8 to find the corresponding parameter values t t1 t2 mODi X039Xi mlDi 1 L2 X1 mlDi39X1 mlDi Substitute the parameter values t t1 t2 into the equation of the line L to find the intersection points R1R2 of the line and the cone R1 LtlPtiv i12 u IJL ss s s 2 line with 2 bounded cylinder rst intersect the line with the planes of the two bounding disks u sss isrss points lie inside the bounding disks then the line cannot intersect the surface of the nite cone otherwise use the prece 39 21 orithrn to nd the intersecu39on points of the line with the in nite cone and discard those intersections that are not within ounds of the nite cone Details me left as an exercise for she reader see Exercise 3 44 Ellipsoids Ellipsicsl Cylinders sud Ellipsicsl Cones The ellipsoisl is ascalesl sphele circular cone one simple 5 y 39 scaling so uansform shese surfaces so she corresponding rasural quaslrics perform she surface i a v is sssusi For example she ellipsoisl can be represerisesl by a cersser poins c shree orthogonal unit axis vecsors mw 394 39 39 39 1175 quot 39 po39 y in she is slirecsiori b in she v slirecsiorL aml c in she w slirecu39or maps she sphere wish cehser c aml Figures unit sphere scales nonmnifonnly abous she censer poiris c by Us in she is slirecu39ou 117 in she v slirecu39ori arul 1 in she w slirecu39ori Figure 5 The ellipsoisl is she image of she sphere under nonuniform scaling s s u AIMNEJVSI s ellipsoisl aml she sphere as corresponding poiriss We know for any poins P on she sphere how so compuse N5 P e c Now we can easily compuse NE since by she resulss inlecsure 18 13 NENSM T where M u is the upper 3 X 3 submatrix of M Intersection points between a ray L and an ellipsoid E are similarly easy to compute Simply intersect the ray L M1 with the unit sphere centered at C using the algorithm in Section 41 If R1R2 are the intersection points of L M1 with the unit sphere then R1M R2 M are the intersection points of L with the ellipsoid note that the parameter values of the intersection points are the same for the sphere and the ellipsoid Analogous strategies can be applied to nd the normal vectors and the ray surface intersection points for the elliptical cylinder and the elliptical cone by applying non uniform scaling transformations to the right circular cylinder and right circular cone We leave the details as simple exercises for the reader see Exercises 24 5 General Quadric Surfaces A general quadric surface is the collection of points satisfying a second degree equation in x yz that is an implicit equation of the form QxyzsAx2ByzC122ny2Eyz2sz2Gx2HyZIzJ0 We can rewrite this equation in matrix notation Let Pxyz1 A D F GW D B E H Q F E C I G H I J Then it is easy to verify that PQPT sz By2C122ny2Eyz2sz2Gx2HyZIz J Thus in matrix notation the equation of a quadric surface is P QPT 0 For this reason we will typically represent quadric surfaces by symmetric 4 X 4 matrices Q The normal vector to an implicit surface is parallel to the gradient For a quadric surface Qxyz Ax2 ByzC122ny2Eyz2sz2Gx2HyZIzJ the gradient 14 VQxyz2Ax DyFzG DxByEzH Fx EyCz 1 Therefore the normal vector NxyzAxDyFzG DxByEzHFxEyCzI Equivalently in matrix notation NxyzPQ4x3 51 where Q4x3 consists of the first three columns of Q To intersect a line Mt P tv with a quadric surface Q we can use the quadratic formula to solve the second degree equation um QLtT 0 The real roots of this equation represent the parameter values along the line Mt of the intersection points The actual intersection points can be computed by substituting these parameter values into the parametric equation Lt P tv for the line Af ne and projective transformations map quadric surfaces to quadric surfaces To find the image of a quadric surface Q under a nonsingular transformation matrix M recall that for any implicit surface F P 0 the equation of the transformed surface is Fm P FP M1 52 For a quadric surface represented by a symmetric 4 X 4 matrix Q Equation 52 becomes PQnew PT 10 M 1QP M391T PM391Q MTp Therefore Qnew M 1 Q M T 53 is the matrix representation of the transformed surface There are many different types of quadric surfaces In addition to the natural quadrics the sphere the right circular cylinder and the right circular cone and their elliptical variants there are also parabolic and hyperbolic cylinders elliptical and hyperbolic paraboloids and hyperboloids of one or two sheets In Table 1 we list the equations of the different types of quadric surfaces in canonical position that is with center at the origin and axes along the coordinate axes Special ray tracing algorithms for the natural quadrics and their elliptical variants are presented in Section 4 The reason that these special ray tracing techniques are effective is that it is easy to represent the natural quadrics in arbitrary positions geometrically without resorting to equations But it is not so natural to represent general quadric surfaces such as paraboloids and hyperboloids in arbitrary positions geometrically without resorting to equations and even if such geometric representations were feasible straightforward intersection algorithms are not readily available Rather than start with a quadric surface in general position typically one starts with a quadric surface in canonical position and then repositions the surface by applying a rigid motion M 15 Now there are two ways we can proceed to ray trace a quadric surface in general position We can compute the equation of the surface and the surface normal in general position from the equation of the surface in canonical position using Equations 51 and 53 We can then solve a general second degree equation to find the intersection of the ray and the quadric surface Alternatively if we store the transformation matrix M along with the equation of the surface in canonical position then we can compute the normal to the surface in arbitrary position from the normal to the surface in canonical position from the formula Nnew old MllT The normal Nold to the surface in canonical position is parallel to the gradient and this gradient is easy to compute because the canonical equation is simple Similarly to intersect a line L with a quadric surface in general position we can intersect the line L M 1 with the quadric surface in canonical position and then map these intersection points back to the desired intersection points by the transformation M Again since the equation of a quadric in canonical position is simple the quadratic equation for the intersection of a line and a quadric in canonical position is also simple Sphere Right Circular Cylinder Right Circular Cone 2 2 2 2 2 2 2 2 2 2 2 x y z R 0 x y R 0 x y cz 0 Ellipsoid Elliptical Cylinder Elliptical Cone 2 2 2 2 2 2 2 x 2y 2Z 2 10 x 2y 2 10 x 2y 2 z20 a b c a a b Parabolic Cylinder Hyperbolic Cylinder Elliptical Paraboloid 2 x 2 y 2 x 2 x 4PY0 2 2 10 2 2 Z0 a b a b Hyperbolic Paraboloid Hyperboloid of One Sheet Hyperboloid of Two Sheets 2 2 2 2 2 2 2 x x z x z 7 y 2 10 7 y 2 7 10 2y 2 10 b a b c a b c Table 1 Equations of quadric surfaces in canonical position 6 Tori The torus is the next most common surface in Computer Graphics after the plane and the natural quadrics A torus can be represented geometrically by a center point C an axis vector A and two scalar radii da see Figure 6 Cutting the torus by the plane through C orthogonal to A generates two concentric circles with center C on the surface of the torus The scalar d represents the radius of a third concentric circle midway between these two circles that is a circle inside the torus We call this circle the generator of the torus The surface of the torus consist of all points at a fixed distance a from this generator Thus the scalar a is the radius of the toroidal tube 16 Figure 6 The torus p lp nnl nlal The clrcle at a dlstance d from the center of the torus ln the plane To flnd the rrnplrcrtequahon of the torus project an arbrtrary pornt P on the torus orthogonally rnto the plane of the generator Then the pornt R the lmage pornt Q and the pornt R lylng on the Q m a nghtmangle whose hypotenuse has length a see Flgure o Thusby the Pythagorean theorern Piglz giklhaz 51 BuHPiglls h A b the axls vector A whlch ln turn ls just the length of the parallel projecuon of the vector P 76 on A Therefore lP79lrP7CA Moreover lQrRllQrCl4 5 Z and l Q 7 c l ls juSL the length of the perpenchcular component of the vector P 7 wth respect to A Therefore lgicllP70il P7Cl2 Pic39J39Af 64 Equauons 1v torus ln general posltlon 2 PeaA t lpeclzelPro39A r 55 v 44 human fawn nm to Plane out of Fungalan n7 CW 17 Because of the square root this equation is actually degree four in the coordinates x yz of the point P since to clear the square root we must square the equation We can also find the normal N to the surface of the torus at the point P by a geometric argument Cut the torus by the plane determined by the point P and the axis of the torus The intersection of this plane and the torus consists of two circles one of these circles passes through the point P The center of this circle is the point R on the generator of the torus and the vector P R from R to P is orthogonal to the surface of the torus Thus we need to find the pointR To locate the point R observe that R is on the line from Q to C and Q CP C P CAA Let q be the distance from Q to C Then by the Pythagorean theorem qQ CquotP C2 P C39A2 R CdqQ C Therefore the normal to the torus is given by NP RP C dqQ C 66 Thus To intersect a line Mt P tv with a torus we simply substitute the parametric equations of the line into the implicit equation for the torus and solve the fourth degree equation 2 Lt cA2 Mm C I2 Lt CA2 d a2 67 The real roots of this equation represent the parameter values along the line of the intersection points As usual the actual intersection points can be computed by substituting these parameter values into the parametric equation Mt P tv for the line The implicit equation for the torus in general position is somewhat complicated Often as with general quadric surfaces it is easier to begin with a torus in canonical position with center at the origin and axis along the z axis and then apply a rigid motion to relocate the torus to an arbitrary position and orientation This approach also works for an elliptical torus since we can include non uniform scaling along with the rigid motion To find the implicit equation of the torus in canonical position substitute C 000 and A 001 into Equation 65 the implicit equation of the torus in general position Squaring to eliminate the square root and simplifying the algebra we arrive at the fourth degree implicit equation for the torus in canonical position 2 TxyzE x2 y2 12 d2 a2 4d2z2 4a2d2 0 68 18 The normal vector Nx y z to the surface Tx y z is given by the gradient Therefore 0T 0T 0T Nxyz 4xGxyz 4yGxyz 4zGxyz2d2 Bx By Bz 69 Gxyz x2 y2 12 d2 a2 To reposition the torus so that the center is at C and the axis is oriented along the direction A rotate the z axis to A and then translate the origin to C These transformations are given explicitly by the matrices see Lecture 13 1 rotu 0 cos01 1 0030uT u sin 004 X I J transC C kxA IkxAl and cos0 k39A where u Now we can find normal vectors on the surface of the torus in general position simply by transforming the corresponding normal vectors from canonical position Thus N general position canonical position r0111quot 9 Recall that rotu 0T r0tu0 so we do not have to take the inverse transpose Similarly we can intersect lines with the torus in general position by transforming the lines to canonical position via the inverse transformation M1 tranA C r0tu 0 intersecting the transformed lines with the torus in canonical position and then transforming the intersection points back to general position using the forward transformation matrix r0104 0 0 transC 1 39 61 Bounding the Torus Ray torus intersections are expensive to compute because to find the intersection points of a line and a torus we must solve a fourth degree equation However the torus is a bounded surface so many lines fail to intersect the torus Thus to speed up our computations we would like to have fast rejection tests to determine when a line does not intersect the torus We can develop such fast tests by bounding the torus with simpler surfaces Consider a torus represented by a center point C an axis vector A and two scalar radii d a as in Figure 6 We can bound this torus on the outside by a sphere with center C and radius d a see Figure 7 left Any line that fails to intersect this sphere will surely fail to intersect the torus Since we have fast tests for determining whether or not a line intersects a sphere this approach provides a fast rejection test when intersecting a line and a torus 19 Nevertheless lines that do intersect this sphere may still fail to intersect the torus by passing above or below the planes bounding the torus or by going through the hole at the center of the torus To eliminate many of the lines passing through the hole in the torus consider the cylinder of radius d a whose axis line is the axis of the torus and whose height above and below the center point C is a see Figure 7 right Any line that passes through the interior of this cylinder will fail to intersect the torus To detect this case consider the disks at the top and the bottom of this bounded cylinder Any line that intersects both of these disks cannot intersect the surface of this bounded cylinder and hence cannot intersect the torus Since we have fast tests for determining if a line intersects these disks see Section 422 this approach provides a fast test for rejecting many of the lines that pass through the hole in the torus We can also use cylinders to bound the torus on the outside Consider the cylinder of radius d a whose axis line is the axis of the torus and whose height above and below the center point C is a Any line that fails to intersect this bounded cylinder will surely fail to intersect the torus see Figure 7 middle To test whether or not a line intersects this bounded cylinder we first compute the intersection points of the line with the surface of the infinite cylinder If both intersection points lie above the plane bounding the cylinder from above or below the plane bounding the cylinder from below then the line cannot intersect the bounded cylinder Since there are fast tests for determining if a point lies above or below a plane this approach provides another fast test for rejecting lines that fail to intersect the torus This cylinder is often a tighter bound to the torus than the sphere so this approach may speed up the ray tracing computation by eliminating more lines Below is pseudocode for the fast rejection tests for the Line Torus intersection algorithm Fast Reiection Tests for Line Torus 39 quot Input C 2 Center Point of the Torus A 2 Unit Direction Vector Parallel to the Axis of the Torus d Radius of the Generator of the Torus a 2 Tube Radius P 2 Point on the Line L v 2 Unit Vector in the Direction of the Line L Algorithm If there are no intersections between the line L and the sphere with center C and radius d a bounding the torus then there are no intersections between the line L and the torus If Dist2C L gt d a2 then the L line does not intersect the torus Otherwise if the line L is parallel to the plane determined by the point C and the unit normal vectorA that is if v 39 A z 0 then If the distance from the line L to the plane determined by the point C and the normal vector A is greater than a there are no intersections between the line L and the torus 20 If v I A 0 and FF 7C39 Agta then the line L does not intersect the torus Otherwise find the intersections E1 E2 of the line Lwith the planes determined by the points C r a A and C a A and the normal vector A that bound the torus above and below If the points E1 E2 lie inside the disks bounding the inner cylinder above and below then there are no intersections between the line L and the torus If Di512E1C 7 aA lt d 7 a2 and Di512E2 C aA lt d 7 a2 then the line L does not intersect the torus Otherwise if the points E1 E2 lie outside the disks bounding the outer cylinder above and below If Di512E1C 7 aA gt d a2 and Di512E2C aA gt d a2 then Find one intersection point D and the corresponding parameterz of the line E1 E1 1E2 7 E1 with the cylindrical surface bounding the torus on the outside 77 that is the infinite cylinderwith radius d a and the same axis line as the torus If 1lt 0 or 1gt 1 then the line L does not intersect the torus Figure 7 A sphere left and a cylinder center bounding a torus on the outside and a cylinder right surrounding the hole to the torus on the inside Notice that the cylinder is a tighter fit than the sphere to the torus on the outside If these fast rejection tests all fail then you will need to intersect the line with the torus To intersect a line and a torus you must solve Equation 67 an equation of degree four in the parameter 1 There are two ways to proceed either solve analytically or perform a binary search Solving analytically requires using the formula for the roots of a degree 4 equation this formula can e found in stan ar algebra texts To perform a binary search first find the parameter values where the line intersects the bounding sphere or the bounding cylinder Then using substitution search for intermediate parameter values where the implicit equation Equation 67 changes sign An intersection point must occur between any two parameter Wlues where Equation 67 takes on opposite signs You will need to pick a tolerance at which to terminate the search Note that for each line you may find anywhere between zero and four intersection points 7 Sur races of Revolution A quaL e of momma ls a surface genemted by rocanng a planar curve called me dxrecmx by planes onnogonal to the axis of revoluuon are Clrcles Spheres nght clrcular cyllnders ngrl clrcular cones and on are all examples of surfaces of revoluuon see Table 2 Surfaces of revolunon howeven are modeled most easrly uslng pararnemc equauons Conslder a pararnefnc curve mm fu gu m are xzrplme Rocaung th5 curve about the axis genemtes me pararnemc surface RUIN fuCOS rfu SHAME 71 see Flgure 8 lf we flx a pdrarnefer u z u then the plane 1 z gmquot lnlersecfs the surface Rum m the Clrde m 3 rm cosmr u slnv gu wth center 103110 and radrus fu Smce x2 yz fins Thus cross secqu of me surface Rum by planes perpendrcular to the axis are rndeed crrcles so me pammemc surface Rum us to genemte slmple pararnefnc equauons for cyllnders cones spheres and on x e an gures Surface of revoluuon Rum wth dlrecmx Dlu Directrix Surface of Revolution Line Du 1 014 Cylinder Ruv cosv sinv u Line D04 Cone Ruv ucosv usinv u Circle Du cosu0sinu Sphere Ruv cosucosv cosusinv sinu d acosucosv C1rcle Du d acosu0as1nu Torus Ruv d acosus1nv as1nu Table 2 Directrix curves that are lines and circles together with the corresponding surfaces of revolution The axis of revolution is the z axis We are not restricted to surfaces of revolution whose axis of revolution is the z axis To extend our parametric equations to general position we first rewrite the parametric equations of the directrix and the surface of revolution in vector notation Du Origin f ui gu k Ruv Origin fucosvi fusinvj guk Rotating the unit coordinate axis vectors i j k to three arbitrary orthogonal unit vectors CBA and then translating the origin to an arbitrary point E we arrive at the parametric equations of the directrix and the surface of revolution in general position Du E fuC guA Ruv E fucosvC fusinvB guA Notice that here the axis of revolution is parallel to the vector A and the directrix lies in the plane of the vectors A and C The vectors B and C are orthogonal unit vectors perpendicular to the axisA There is not much difference between working in canonical position and working in general position for surfaces of revolution since we can always transform from canonical position to general position by the rigid motion Col BO A0 E 1 Therefore for the remainder of this discussion we will consider surfaces of revolution in canonical M position where the axis of revolution is the z axis The normal vector to a parametric surface is parallel to the cross product of the partial derivatives For the surface of revolution in Equation 71 Ruv fucosv fusinvgu 23 BR E f ucosvfus1nvgu BR 3 fu sinv fu cosv 0 Therefore BR BR Nuv 5x 5 fug ucosv fug us1nvfuf u To ray trace a surface of revolution we need to intersect a surface of revolution with straight lines A surface of revolution Ruv f ucosv fusinvgu intersects a line m At B Axt BxAytByAzt Bz at parameters where Ruv M t or equivalently where fucosv fusinv gu Ax t Bx Ayt ByAzt Bz Thus to find the intersection of a line and a surface of revolution we need to solve three simultaneous nonlinear equations with three unknown tu v The simplest of these three equations is the z equation since only two parameters ut appear in this equation Solving the z equation Azt Bz gu for tyields t 800 31 72 Az so we can eliminate one of the variables If t is horizontal then Az 0 and we can solve gu Bz directly for 14 Next summing the squares of the xy equations and invoking the trigonometric identity cos2v sin2v 1 yields 2 2 2 f uAxtBx AytBy 73 Since we already know I as a function of u from Equation 72 we can reduce Equation 73 to one unknown We then solve Equation 73 for u usually by numerical methods The corresponding t parameters can now be computed from Equation 72 Finally taking the ratio of the x and y equations yields 24 A tBy Y tanv AxtBx so A tB vtan1 74 AxtBx The only bottleneck in this intersection algorithm is solving Equation 73 If f u gu are trigonometric functions as is the case for the sphere and the torus in Table 2 then this equation contains transcendental functions and may be difficult to solve There is a trick however for replacing sines and cosines by rational functions Let s tanu 2 Then 1 cosu cos2u 2 sin2u 2 2cos2u 2 1gt cos2u2 1 2 32 1tan2u21 sec2u2 2 cos u2 1 00504 Solving for cosu we find that 1 32 2s cosu j and s1nu 7 1 3 1 3 Replacing sine and cosine with rational functions often leads to faster computations Moreover it is generally easier to solve polynomial equations than to solve trigonometric equations If the directrix is an unbounded curve then the method outlined above intersects a line with an unbounded surface of revolution But just like cylinders and cones most surfaces of revolution that appear in Computer Graphics are closed and bounded To intersect a line with a surface of revolution bounded above and below by a pair of disks we must discard any intersections that are above or below the planes that contain these disks We must also intersect the line with the planes of the two bounding disks and then test to see whether or not these intersection points lie inside these disks The details are similar to the ray tracing algorithms for the bounded cylinder and the bounded cone and are therefore left as an exercise for the reader see Exercise 17 8 Summary In this lecture we have concentrated on the simplest mathematical surfaces those surfaces most common in Computer Graphics 0 planes and convex polygons natural quadrics and their elliptical variants 25 spheres and ellipsoids right circular cylinders and elliptical cylinders right circular cones and elliptical cones general quadric surfaces both parabolic and hyperbolic parabolic cylinders and hyperbolic cylinders paraboloids and hyperboloids tori and surfaces of revolution For each of these surfaces we have shown how to compute their surface normals as well as how to calculate their intersections with straight lines With these results in hand ray tracing these surfaces is a straightforward task In the next lecture we shall extend our discussion from surface modeling to solid modeling Solids are bounded by surfaces so many of the surfaces that we have discussed here will reappear in our discussion of solid modeling Ray tracing which is a powerful technique for rendering surfaces will also reappear as a potent technique for analyzing solid models Exercises 1 Show that a pointR in the plane of AP1P2P3 lies inside AP1P2P3 if and only if all three of the barycentric coordinates of R with respect to AP1P2P3 are positive See Lecture 4 Exercise 24 for a definition of barycentric coordinates 2 Explain in detail how to ray trace an elliptical cylinder In particular explain how you would i model the elliptical cylinder ii compute the surface normals to the elliptical cylinder iii find ray surface intersections for the elliptical cylinder Treat both the bounded and unbounded elliptical cylinder 3 Develop an algorithm to intersect a straight line with a right circular cone bounded by a two disks b one disk and the cone vertex 4 Explain in detail how to ray trace an elliptical cone In particular explain how you would i model the elliptical cone ii compute the surface normals to the elliptical cone iii find ray surface intersections for the elliptical cone Treat both the bounded and the unbounded elliptical cone 26 5 Let Ds x syszs be a parametrized curve lying in a plane in 3 space and let v v1 v2 V3 be a fixed vector in 3 space not in the plane of Ds The parametric surface Cst Ds tv is called the generalized cylinder over the curve Ds see too Lecture 18 Exercise 2 Suppose that you already have an algorithm to compute the intersection points of any line in the plane of Ds with the curve Ds Based on this algorithm develop a procedure to find the intersection points of an arbitrary line in 3 space with the surface Cs t 6 Let Ds x syszs be a parametrized curve lying in a plane in 3 space and let Q 611612613 be a fixed point in 3 space not in the plane of Ds The parametric surface Cs t 1 tDs IQ is called the generalized cone over the curve Ds see too Lecture 18 Exercise 3 Suppose that you already have an algorithm to compute the intersection points of any line in the plane of Ds with the curve Ds Based on this algorithm develop a procedure to find the intersection points of an arbitrary line in 3 space with the surface Cs t 7 Let U1s U2s be two curves in 3 space The parametric surface Rs t 1 tU1s tU2s is called the ruled surface generated by the curves U1sU2s see too Lecture 18 Exercise 4 Explain how you would find the intersection points of a ruled surface Rs t with an arbitrary straight line 8 Let Rs R su and P t P tv be two intersecting lines in 3 space Let vi be the component of v perpendicular to u a Show that the lines Rs and P t intersect at the parameter value t R P 39 vi v 39 vi b Use the result of part a to find the parameter value where the line and the cylinder intersect without resorting to the inversion formula for the line L i t c Use the result of part a to find the parameter value where the line and the cone intersect without resorting to the inversion formula for the rational linear parametrization of the line Lt 9 Let R x0y0zo 1 be a point on a quadric surface represented by a symmetric 4 X 4 matrix Q Show that the equation of the plane tangent to the quadric Q at the point R is given by R Q PT 0 27 10 Find the symmetric 4 X 4 matrices representing each of the quadric surfaces in Table 1 11 Compute the mean and Gaussian curvature see Lecture 18 for each of the quadric surfaces in Table 1 12 Compute the mean and Gaussian curvature see Lecture 18 for a torus in canonical position in two ways i from the implicit equation ii from the parametric equation 13 A cyclide is a surface whose lines of constant curvature are all either circles or straight lines T he torus is a special case of a cyclide The equation of a cyclide in canonical position centered at the origin with axes aligned along the coordinate axes is 2 Fxyz x2 y2 z2 d2 13 4ax cd2 4b2y2 0 where abc d are constants such that cd 2 0 b gt 0 and a2 b2 02 a For the cyclide in canonical position explain how you would i compute the normal vector at the point x y z ii find the intersection points with an arbitrary straight line b For a cyclide in arbitrary position a cyclide with center at the point C and axes aligned along three mutually orthogonal unit vectors uv w explain how you would i model the cyclide ii compute the normal to the cyclide at the point x yz iii find the intersection points of the cyclide with an arbitrary straight line 14 Consider a surface whose cross sections by planes perpendicular to a fixed line L are ellipses whose centers lie on the line L and whose major axes are all parallel to each other Explain how you would a model this surface b compute the normal to this surface at an arbitrary point on the surface c find the intersection of this surface with an arbitrary straight line 15 Consider a surface of revolution Ruv fu cosv fu sinvg 14 Suppose that there is a function F u such that Fgu u a Show that the implicit equation of Ruv is given by x2 y2 Fz 28 b c Find the function F u for each of the surfaces of revolution in Table 2 Using the results of part 17 nd the implicit equation for each of the surfaces of revolution in Table 2 16 Consider the parametrizations in Table 2 of the cylinder the cone the sphere and the torus a Using the substitution t tanv 2 find parametrizations for the cylinder and the cone that do not involve trigonometric functions Using in addition the substitution 3 tanu 2 find parametrizations for the sphere and the torus that do not involve trigonometric functions 17 Develop an algorithm to intersect a straight line with a surface of revolution bounded by two disks Programming Projects 1 Recursive Ray Tracing Implement a recursive ray tracer in your favorite programming language using your favorite API a Include at least the following surfaces Tetrahedra and Cubes Natural Quadrics and their Elliptical Variants 3 Tori Use several light sources along with the following lighting models 0 Ambient Light 0 Diffuse Reflection Specular Reflection Incorporate both reflection and refraction Incorporate a spotlight see below A spotlight is a focused point light source at a finite distance from the scene The light cone of the spotlight is specified by the following parameters see Figure 9 0 C cone vertex 2 location of light source 0 A cone unit axis vector 0 y cone angle The lighting formulas for a spotlight are the same as the lighting formulas for a point light source except that the diffuse and specular components are attenuated by a factor 0130 Thus for a spotlight Idi use cgpollpkdL39 N specular cgpoleksae 39 V 29 0 L 2 direction to light source 0 N normal vector to surface 0 V 2 direction to eye 0 R 2 direction of re ection vector 2 2L 39NN L 0 A spotlight cone axis vector 0 y spotlight cone angle csp0l L39A L39A2cosy 0 otherwise e exponent controlling falloff in intensity from center of spotlight user defined A Light Cone C Spotlight Figure 9 The light cone for a spotlight 2 Camera Obscura A camera obscura is the technical term for a pinhole camera In a camera obscura the film is behind the aperture Placing the film behind the aperture is equivalent to placing the screen behind the eye rather than in front of the eye a Use recursive ray tracing to simulate a camera obscura b How does the image differ from the image generated by standard ray tracing Tutorial 3 OpenGL APIs for Drawing in 3 Dimensions Fall 2005 Overview Up until now you have used OpenGL to draw points7 lines7 and buffers of pixels in 2 dimensions In project 4 you have to implement a viewer for 3d models in OpenGL7 which means you will need to interact with the library more extensively This tutorial is a crash course in the APls you will need This tutorial is only intended as an overview I commend to you the OpenGL Red Book as the real authority on the APls discussed today APIs for Drawing 0 glVertex You have already used the 2 dimensional glVerteX commands to put points on the screen in 2D For this lab you will also need to use the 3 dimensional equivalents for example7 glVerteXSf O with 3 oating point arguments o glNormal3 Smooth Gouraud shading requires that every vertex of a model have its own normal The valid type suf xes are the same as for glVerteX37 for example7 glNormale takes 3 oats as arguments o ngeginO glEndO Calls to glVerteX and glNormal should fall between calls to ngeginGLTRIANGLES and glEnd Remember that the le format for lab 4 de nes models made only of triangles o nghadeModel This function takes one of two arguments GLFLAT and GLSMDDTH These calls enable at and Gouraud shading7 respectively 0 glPolygonMode One function ofthis API is to enable or disable wireframe rendering To do this7 pass the following arguments glPolygonMode GLFRDNTANDBACK GLLINE enable wireframe glPolygonMode GLFRDNTANDBACK GLFILL return to normal rendering APIs for Projection o gluPerspective A utility function to create a perspective projection Already called in UpenGLFrame Cpp o gluLookAt A utility function for orienting the viewport or camera used by OpenGL There are 9 oating point arguments the coordinates of the cameras forward vector the coordinates of a location the camera is looking at and the coordinates of a vector pointing up from the camera APIS for Lighting Properties 0 glLightModel Set general properties of the lighting model For example the fol lowing code snippet sets the color of the ambient scene lighting to 05 05 05 GLfloat ambientlight4 05 05 05 10 glLightModelfvGLLIGHTMDDELAMBIENTambientlight o glLight Set properties of speci c lights You will use this to set the color and location of the lights in your scene For example GLfloat lightdiffuse 10 10 10 10 g1L1ghtfvltGLLIGHT0 GLDIFFUSE lightdiffuse This sets the diffuse color of GLLIGHTO to 101010 There are a couple of things to note here First we de ne only a single color for each light while OpenGL recognizes distinct ambient diffuse and specular contributions for each light For normal lights such as what we expect the ambient contribution is 0 and the diffuse and specular contributions are both equal to the color of the light You may have noticed that both the examples given above pass arrays of 4 oats as color arguments Colors in OpenGL have a fourth component called alpha which is used for blending and transparency You may ignore this fourth coordinate OpenGL de nes at least 8 light GLLIGHTO through GL1LIGHT7 When you have de ned the properties and location of a light be sure to call glEnable GLLIGHTO When you switch away from your OpenGL renderer you will need to disable lighting do this with ngisable GLLIGHTING To turn lighting back on call glEnable GLLIGHTING APIS for Material Properties 0 glMaterial Set various material propertiesi that is de ne the color and lighting properties of the geometry that OpenGL draws Note that as it does with light colors OpenGL recognizes distinct ambient diffuse and specular colors for the material but our inputs give only one coef cient for each The way around this is to use the same number for each RGB component in the color settings For example float diffuse the diffuse coefficient for the model float diffcolor4 diffcolor0 diffcolor1 diffcolor2 diffuse diffcolor3 1 glMaterialfvGLFRUNT GLDIFFUSE diffColor Consult the Red Book for the other arguments to pass to glMaterial o glC010r3f You are familiar with this function Since each of our models is only one color7 you will only need to call this function once per rendering pass Lecture 3 Some Strange Properties of Fractal Curves I have been a stranger in a strange land Exodus 222 1 Fractal Strangeness Fractals have a look and feel that is very different from ordinary curves Unlike commonplace curves such as lines or circles there are no simple formulas for representing fractals like the Sierpinski gasket or the Koch curve Therefore it should not be surprising that fractal curves also have geometric features that are unlike the properties of any other curves you have previously encountered In this lecture we are going to explore some of the strangest peculiarities of fractals including their dimension differentiability and attraction 2 Dimension You may have been wondering about the origin of the term fractal Many fractal curves have a nonintegral dimension a fractional dimension somewhere between one and two Fractal refers to this fractional dimension Standard curves like the line and the circle are 1dimensional To say that a curve is 1 dimensional means that the curve has no thickness if the curve is black and the background is white then when we look at the curve we see white on either side of a thin black band see Figure 1 But fractals are different look at the Sierpinski gasket or the C curve in Figure 1 There seem to be regions that are neither black nor white but instead are gray Such curves typically have dimension greater than one but less than two these curves do not completely fill up any region of the plane so they are not 2dimensional but neither are these gray curves as thin as idimensional curves To calculate the actual dimensions of fractal curves we first need to formalize the notion of dimension for some standard geometric shapes Figure 1 For the line and the circle there is a clear distinction between the curve black and the background white But for fractals like the Sierpinski gasket and the C curve the curve black and the background white interpenetrate and there are gray regions where the distinction between the curve and the background is not so clearly defined The dimension of a line segment is one the dimension of a square is two and the dimension of a cube is three There is a formal way to capture these dimensions Suppose we split these objects by inserting new vertices at the centroids of their edges and faces Then the line segment splits into 2 line segments the square into 4 22 squares and the cube into 8 23 cubes see Figure 2 In each case the dimension appears in the exponent There is nothing magical about splitting each edge into two equal parts If we split each edge into N equal parts then the line segment splits into N line segments the square into N 2 squares and the cube into N 3 cubes Once again the dimension appears in the exponent Another name for an exponent is a logarithm so we are going to formalize the notion of dimension in terms of logarithms Figure 2 Inserting vertices at the centroids splits a line segment into 2 line segments a square into 4 22 squares and a cube into 8 23 cubes Another way of thinking about what we have just done is that we have split the line the square and the cube into identical parts where each part is a scaled down version of the original This decomposition should remind you of the fractals that you encountered in Lecture 2 where each fractal is composed of several identical scaled down copies of the original fractal Evidently in this construction for the line the square and the cube if D denotes dimension then L0 E DL0gNE 539 1 L0gN where N is the number of line segments along each edge and E is the number of equal scaled down parts But if N is the number of line segments along each edge then S UN is the scaling along each edge Since 105709 L0gN we can rewrite Equation 1 by setting L0gE 10 S i where S is the scale factor and E is the number of identical scaled down parts 2 Equation 2 has several important properties First notice that Slt1 so L0gSlt0 Therefore the minus sign on the right hand side of Equation 2 insures that the dimension D is positive Second since D is defined as the ratio of two logarithms the base of the logarithm does not matter dimension is the same in all bases Finally Equation 2 gives the same result as 2 Equation 1 for the line the square and the cube since in these cases E ND and S 1 N so L0gE L0gND DLOgN L0gS LoglN L0gN Let s see now what happens when we apply Equation 2 to fractal curves 21 Fractal Dimension To apply our dimension formula we need to consider selfisimilar curves Recall that a curve is selfsimilar if the curve can be decomposed into a collection of identical curves each of which is a scaled version of the original curve Most of the fractal curves we encountered in Lecture 2 such as the Sierpinski gasket and the Koch curve are selfisimilar curves In fact selfisimilarity is what allows us to write simple recursive turtle programs to generate these curves Let s look now at some examples Example 1 Sierpinski Gasket The Sierpinski gasket consists of three smaller Sierpinski gaskets where the length of each edge of the smaller gaskets is oneihalf the length of an edge of the original gasket see Figure 3 left Thus E3and Sl2so LogltEgt Logo Logo LogS L0g12 39 L0g2 al585lltDlt2 Example 2 Koch Curve The Koch curve consists of four smaller Koch curves each oneithird the size of the original curve see Figure 3 right Thus E 4 and S 13 so LogltEgt Loglt4gt Loglt4gt LogS L0g1 3 L0g3 al262 1ltDlt2 1quot miquot 5quot r39 h 5 In 11m in 32mm The Sierpinski gasket left and the Koch curve right The Sierpinski gasket is composed of three selfisimilar parts the length of each edge of one of the smaller gaskets is one half the length of an edge of the original gasket The Koch curve is composed of four selfisimilar parts each oneithird the size of the original Koch curve Figure 3 22 Computing Fractal Dimension from Recursive Turtle Programs The fractal dimension of a self similar fractal curve can often be computed directly from its recursive turtle program the number of recursive calls corresponds to the number E of equal self similar parts and the scale factor in the RESIZE command corresponds to the scale factor S Thus LogRecursiveCalls 3 LogScaleFactor I This formula like Equation 2 is valid provided that the self similar parts do not overlap To illustrate the validity of this formula let s revisit the fractal dimension of the Sierpinski gasket and Fractal Dimension the Koch curve Example 3 Sierpinski Gasket Recall from Lecture 2 that in the recursive turtle program for the Sierpinski gasket Recursive Calls 3 and ScaleF actor 1 2 so Log Recursive Calls Log3 Log3 Fractal Dimension Log Scale Factor Log1 2 Log2 Example 4 Koch Curve Again recall from Lecture 2 that in the recursive turtle program for the Koch curve RecursiveCalls 4 and ScaleFactor 1 3 so LogRecursiveCalls ng4 L0g4 LogScaleFactor Log1 3 Log3 Fractal Dimension 3 Differentiability A curves is said to be smooth or differentiable if the curve has a well defined slope or equivalently a well defined tangent at every point Lines and circles are smooth curves Polygons and stars are piecewise smooth curves polygons and stars have well defined slopes everywhere except at their vertices The functions you studied in calculus polynomials trigonometric functions exponentials and logarithms are all differentiable functions What about fractals Differentiable functions are everywhere continuous but continuous functions need not be everywhere differentiable The function y x represents a continuous curve composed of two lines the line y x for x s 0 and the line y x for x 2 0 see Figure 4 Thus y x has slope 1 for x lt 0 and slope 1 for x gt 0 but the slope of y x is not well defined at the origin A curve is said to be piecewise linear if like the function y x it is composed of a sequence of straight lines A piecewise linear curve is smooth everywhere except where two lines join Thus it is easy to generate curves that are smooth everywhere except at a nite number of points The level n Koch curve is a piecewise linear curve that is smooth everywhere except at finitely many points 4 Figure 4 The gtaph of y e l x l When 1 isnegstive the slope is 1 when x ispositive slopeis 1 have on a i39 39te number of points whese the slope is not well defined But intuition can be misleading Many fractal chiv2 are continuous everywhere bhlL di39 eremmble nowhere y it seems evident that a continuous curve can Considerthe Izvel erni a mi htlin point T Im u mm 39 theslope is not defined Similarly at level two these are 15 points whese the slope is not defined At level n these ale 4quot 1 points In hot in the limit the slope of the Koch curve is undefined at every point We can 39 39 39 39 39 Snppose L39 L w quot 39 level em is 1 Then the length of the line segments in level one is 13 the length of the line segments in level two is 19 and in genetal the length ofthe line segments at levelnis 3 Thus the lengths Now the curve is le line segments approach zeto Thus in the limit the Koch curve is continuous evesywhete hut 39 39 391quotth 39 39 in fa t used no show mat Facials are indeed very mange curves rm g m In Elma Figure 5 Levels 0 1 2 3 of the Koch curve Level zero is a straight line which is smooth at every point Level one has three points where the slope is not defined level two has 15 points where the slope is not defined and level 3 has 63 points where the slope is not defined Notice too that the lengths of the line segments decrease from level to level by a factor of 3 4 Attraction How precisely does the fractal generated by a recursive turtle program depend on the choice of the base case Intuitively you might think that changing the base case will alter the fractal in some fundamental way But as we have just seen when we investigated differentiability our intuition regarding fractals can often be misleading We shall begin then by considering two familiar examples the Sierpinski gasket and the Koch curve Based on our experience with these two fractals we shall draw some highly counterintuitive and rather remarkable conclusions 41 Base Cases for the Sierpinski Gasket In the base case the standard program for the Sierpinski gasket draws a triangle see Lecture 2 The curves generated by levels 0136 of this program are illustrated in Figure 6 In Figures 7 9 we have changed the base case to draw a square a star and a horizontal line but we have not altered the recursive body of the program Each of these programs generates curves that start out quite different at levels 01 but by level 6 they all seem to be converging to the same Sierpinski gasket 42 Base Cases for the Koch Curve Let s try another example the Koch curve In the base case the standard program draws a straight line The curves generated by levels 0125 of this program are illustrated in Figure 10 In Figures 11 13 we have changed the base case to draw a square bump a square and a square where the turtle repeats the first side after completing her path around the square but we have not altered the recursive body of the program Again each of the curves generated by these programs starts out quite different at levels 01 but except for the program where the base case is a square see Figure 12 we will return to a discussion of this anomalous case shortly below by level 5 they all seem to be converging to the same Koch curve W9 mmm mmmmmmmummmmmmmwm iw iw iw 8 mm mm i i M M M mmma r rlv r rl r V V Vw In N rl 41 LV rl H G Cv w w LVV I2 er n V 5V7 CV V Va mmm mmwmmwmmmmmmmw HmmmeWMHmmmmwm MWWMM r a H z 3 chmd n 21m Figure 10 Levels 0 1 2 5 of the Koch curve The base case is a horizontal line V 53 4x V 3 JDNMG L Figure 11 Levels 0 1 2 5 of the Koch curve The base case is a square bump Figure 12 Levels 0 1 2 5 of the Koch program The base case is a square xx 5 l 1quot Figure 13 Levels 0 1 2 5 of the Koch curve The base case is a square where the turtle repeats the first side after completing her path around the square 43 Attractors When we first encountered recursive turtle programs our intuition lead us to believe that the precise form of the base case is critical for generating the desired fractal curve The natural base case for the Sierpinski gasket is a triangle the natural base case for the Koch curve either a straight line or a triangular bump But the examples we have just witnessed both for the Sierpinski gasket and for the Koch curve indicate that in the limit and as a practical matter after only about five or siX levels of recursion the base case is all but irrelevant Apparently a recursive turtle program will always converge to the same fractal curve independent of the turtle program in the base case When a process converges to the same limit value independent of the choice of the 8 initial value the limit value is called an attractor Fractals are attractors Figure 12 seems to challenge this conclusion here the expected convergence to the Koch curve fails to occur However the reason for this failure turns out to be that the recursion in the body of the turtle program for a bump fractal assumes that the turtle advances to the end of the line on which the bump occurs rather than return to her initial position This assumption is violated by the base case in Figure 12 but is satisfied by the base case in Figure 13 where the turtle repeats the first side of the square after completing her path around the square In future lectures we shall prove that in the limit as the number of levels approaches infinity the fractals generated by recursive turtle programs are indeed independent of the turtle program in the base case provided that the final state of the turtle in the base case is the same as the final state of the turtle in the recursion Usually as in the Sierpinski gasket the initial state and the final state of the turtle are identical but as illustrated by the Koch curve one must always be careful to check this assumption Thus with some mild assumptions the fractal generated in the limit by any recursive turtle program is indeed independent of the turtle program in base case Fractals are attractors Indeed attraction is the signature property by which we recognize fractals But why does such a strange property hold To understand the reason behind this curious phenomenon we shall have to forgo for now our study of Turtle Graphics and investigate instead a very different approach to fractals called iterated mctions systems To understand iterated functions systems we shall first need to take up the study of affine transformations and affine graphics We shall commence with these topics in our next lecture 5 Summary From the turtle s point of view fractals are simply recursion made visible But from our perspective fractals generated from recursive turtle programs can have many strange properties 1 Fractals can be self similar fractals can often be decomposed into a collection of identical curves each of which is a scaled version of the original fractal curve 2 Fractals can be continuous everywhere yet differentiable nowhere 3 Fractals can have fractional dimensions non integer dimensions between one and two 4 Fractals are attractors independent of the base case in the recursive turtle program that generates the fractal These four properties are characteristics of fractal curves that we do not find in common everyday curves together these features are what set fractals apart from our ordinary experience of geometry Exercises 1 Let P denote the perimeter of the nth level of the Koch snow ake a Show that 4 1 Pn Pn1 P 4 P 11 n 0 3 b Conclude that the perimeter of the Koch snow ake is infinite 2 Let A denote the area enclosed by the nth level of the Koch snow ake a Show that i A A0 3A019 492 42934 19 ii LimneooA 8 5A0 b Conclude from Exercise 1 and part a that the Koch snow ake has an infinite perimeter but encloses a nite area c Explain why it is not possible for a curve to have a finite perimeter but to enclose an in nite area 3 Show that the bump fractals corresponding to the bump curves in Lecture 2 Figure 13 are continuous everywhere but differentiable nowhere 4 Consider the following recursive turtle program SQ UARE Level IF Level 2 0 POLY 1 Jr 2 OTHERWISE REPEAT 4 TIMES RESIZE 12 SQUARE Level 1 RESIZE 2 MOVE 1 TURN Jr 2 a Show that as the level approaches in nity this program generates a filled in square b Compute the dimension of the square from this recursive turtle program 5 Compute the fractal dimension of the C curve 10 6 Compute the fractal dimension of the gaskets in Lecture 2 Figure 8 7 Compute the fractal dimension for each of the curves in Lecture 2 Figure 11 8 Compute the fractal dimension for each of the bump fractals corresponding to the bump curves in Lecture 2 Figure 13 9 Generate a fractal pentagonal gasket using the same recursive turtle program with three different turtle programs in the base case 10 Generate the fractal C curve using the same recursive turtle program with three different turtle programs in the base case 11 Generate the fractal tree in Lecture 2 Figure 11 using the same recursive turtle program with three different turtle programs in the base case Lecture 26 Blossoming blossom abundantly and rejoice even with joy and singing Isaiah 352 1 Motivation Linear functions are simple polynomials are complicated If Lt at then clearly LMs At MLs AL t More generally if Mt at b then it is easy to verify that 11 As At 1 ALs ALt In the first case Lt preserves linear combinations in the second case Lt preserves affme combinations But if Pt ant a0 is a polynomial of degree n gt 1 then PMs At MPs AP t Pl A At g 1 APs am Thus arbitrary polynomials preserve neither linear nor affme combinations The key idea behind blossoming is to replace a complicated polynomial function Pt in one variable by a simple polynomial function pu1 u in many variables that is either linear or affme in each variable The function pu1 u is called the blossom of Pt and converting from Pt to pu1 u is called blossoming Blossoming is intimately linked to Bezier curves We shall see in Section 3 that the Bezier control points of a polynomial curve are given by the blossom of the curve evaluated at the end points of the parameter interval Moreover there is an algorithm for evaluating the blossom recursively that closely mimics the de Casteljau evaluation algorithm for Bezier curves In this lecture we shall apply the blossom to derive two standard algorithms for Bezier curves the de Casteljau subdivision algorithm and the procedure for differentiating the de Casteljau evaluation algorithm We shall also derive algorithms for converting between the Bernstein and monomial representations of a polynomial Other properties of Bezier curves such as degree elevation are derived using blossoming in the exercises at the end of this lecture 2 The Blossom The blossom of a degree n polynomial Pt is the unique symmetric multiaffine function pu1 u that reduces to Pt along the diagonal That is p041 u is the unique multivariate polynomial satisfying the following three axioms Blossomin g Axioms i Symmetry pu1 u pua1 ua for every permutation c7 of 1 n ii Multiaffine pu11 xukkau1 xpu1ukuxpu1vku iii Diagonal ptt Pt The symmetry property says that the order of the parameters u1 u does not matter when we evaluate the blossom pu1u The multiaffine property is just a fancy way to say that pu1 u is degree one in each variable see Exercise 4 The diagonal property connects the blossom back to the original polynomial At first these three axioms may seem very abstract and complicated but we shall see shortly that blossoming is both explicit and straightforward We are interested in blossoming because of the following key property which we shall derive in Section 3 relating the blossom of a polynomial to its Bezier control points Dual Functional Properly Let P t be a Bezier curve over the interval a b with control points P0 P Then Pkpaabb k0n n k k We have yet to establish the existence and uniqueness of a function satisfying the three blossoming axioms But before we proceed to prove both existence and uniqueness let us get a better feel for the blossom by computing a few simple examples Example I Cubic Polynomials Consider the monomials 1 t t2 t3 as cubic polynomials It is easy to blossom these monomials since in each case it is easy to verify that the associated function pu1u2ug given below is symmetric multiaffine and reduces to the required monomial along the diagonal Pt1 gt pu1u2u31 ul u2 u3 3 M1112 142113 M3141 Ptt gt Pu1u22 3 Ptt2 gt pu1u2u3 Pt t3 gt pu1u2u3 ulugug 2 Notice that the functions on the right hand side are up to a constant multiple simply the elementary symmetric functions in three variables Notice too that we must decide the degree of each monomial before we blossom since the degree of the monomial tells us how many variables must appear in the blossom Using these results we can blossom any cubic polynomial since Pt a3t3 a2t2 a1ta0 MMMMMM MMM PM1M2au3d3M1M2M3d2dl 1 2 3 a0 Similar techniques can be applied to blossom polynomials of any arbitrary degree n by first blossoming the monomials M I t tk k 0n using elementary symmetric functions in n variables and then applying linearity This observation leads to the following results Proposition 1 Blossoming Monomials The blossom of the monomial M130 tk considered as apolynomial ofdegree n is given by 2 l1 39 i 2 where the sum is taken over all subsets i1 ik of1 n mZu1un k 21 Proof To show that mZu1un is the blossom of M130 we need to verify that the three blossoming axioms are satis ed By construction mZu1un is symmetric since the sum on the right hand side of Equation 21 is taken over all subsets i1ik of 1 n Also the function on the right hand side of Equation 21 is multiaffine since each variable appears in each term to at most the rst power Finally since the number of subset of 1 n with k elements is 2 along the diagonal mZrrM z a k Theorem 2 Existence of the Blossom For every degree n polynomial Pt there exists a symmetric multia ine function pu1 uquot that reduces to Pt along the diagonal That is there exists a blossom pu1 uquot for every polynomial Pt Proof By Proposition 1 the blossom exists for the monomials tk k 0n Therefore since every polynomial is the sum of monomials and since the blossom of the sum is the sum of the blossoms see Exercise 1 a blossom pu1 uquot exists for every polynomial Pt 3 3 Blossoming and the de Casteljau Algorithm A word about notation before we proceed Throughout this lecture especially in the diagrams we shall adopt the multiplicative notation ulnun to represent the blossom value pu1u Though an abuse of notation this multiplicative representation is highly suggestive For example multiplication is commutative and the blossom is symmetric ulnu 1401 mud lt gt pu1u pua1ua Moreover multiplication distributes through addition and the blossom is multiaffine Thus 17 u u a b u u a u a b gt ulnunu u1una b a b a b a b a 144 b and similarly b u u a a b a b a a pu1unb u u b a 17 gt pu1uu b u pu1una b a Since symmetry and multiaffinity are the main properties featured in the diagrams the same diagrams make sense both for multiplication and for blossoming Thus this multiplicative notation for the blossom is both natural and evocative In addition these similarities between multiplication and blossoming suggest that corresponding to identities for multiplication we should expect analogous identities for the blossom In fact we shall see an important example of such an analogous identity in Section 4 where we introduce an analogue of the binomial theorem for the blossom Using this multiplicative notation Figure 1 shows how to compute values of ptt from the blossom values paabb k recurs1vely by apply1ng the multraffrne and n k symmetry properties at each node For example since 17 t t a t b a b a b a it follows by the multiaffine property that pabt p ab btat ab btpaba tapabb b a b a b a b a Similar identities hold at all the other nodes in Figure 1 Now compare the blossoming algorithm in Figure 1 to the de Casteljau algorithm in Figure 2 Clearly Figure 1 is the de Casteljau algorithm for ptt Pt with control points BC pa a b b This observation has several important consequences which we summarize H4 H4 n k k in Theorems 345 m b t a att bit b Xa 177 a t abt aa bbt b y K 17 K 17 Xa aaa dab abb bbb Figure 1 Computing ptt from the blossom values pa ab b k Here we n k illustrate the cubic case and we adopt the multiplicative notation uvw for puvw As usual the label on each edge must be normalized by dividing by b a so that the labels along the two arrows entering each node sum to one Pt t i V39 a 7 g 1739 WV 1 Figure 2 The de Casteljau algorithm for a cubic Bezier curve Pt on the interval ab Compare to Figure 1 Theorem 3 Every Polynomial Curve is a Bezier Curve Every polynomial can be expressed in Bezier form That is for every polynomial Pt and every interval a b there exist control points P0 P such that over the interval a b the polynomial P t is generated by the de Casteljau algorithm with control point P0 P Proof This result follows immediately from Figure 1 since Figure 1 is the de Casteljau algorithm for ptt Pt with control points BC pa ab b k W4 H4 n k Theorem 4 Dual Functional Property of the Blossom Let Pt be a Bezier curve de ned over the interval a b and let pu1 u be the blossom of P t Then Pk kth Bezier Control Point of Pt 31 n k k Proof Again this result follows immediately from Figure 1 Theorem 5 Uniqueness of the Blossom Let Pt be a polynomial of degree n Then the blossom pu1 u of Pt is unique That is for each polynomial Pt there is only one function pu1 u that is symmetric multiaffine and reduces to Pt along the diagonal Proof For any polynomial Pt Figure 3 shows how to compute an arbitrary blossom value pu1 u from the blossom values pa ab b k n by substituting uk for t on the n k k kth level of the de Casteljau algorithm 1 2 3 b 3 ug a au1u2 buluz bur bbu aaul 1 b u K a bV1 aby y a a aab abb bbb Figure 3 Computing an arbitrary blossom value pu1u from the blossom values pa a b b k Here again we illustrate the cubic case and we adopt the g n k k multiplicative notation uvw for puvw As usual the label on each edge must be normalized by dividing by b a Thus every blossom value pu1u is completely determined by the blossom values Paabb k Now suppose that the polynomial Pt has two blossoms n k pu1 u and quiL u Then by the Theorem 4 6 MMM QM since both sidreskrepresent the Be zlier co trol points of Pt and these control points are unique see Lecture 24 Section 52 But we have seen in Figure 3 that any arbitrary blossom value is completely determined by these particular n 1 blossom values Therefore 17M1wa M qM1a Mn so the blossom of Pt is unique 31 Bezier Subdivision from Blossoming The de Casteljau algorithm for subdividing Bezier curves is easy to derive using the dual functional property Equation 31 of the blossom Let Pt be a Bezier curve over the interval d b with control points lbw P By the dual functional Prope y HcPwM k0n To subdivide this Ee ier culi39ve at the parameter I we must find the Bezier control points for Pt over the intervals at and ab Again by the dual functional property these control points Q0 Qquot and R0 Rn are Qk PIAIJ k0n n k k Rk17hJbb k0n 7 But look at Figure 1 If kwe interpret every triple uvw as the blossom value 1704 vw then the control points Qk and Rk emerge along the left and right lateral edges of the triangle Generalized to arbitrary degree this observation is precisely the de Casteljau subdivision algorithm of Lecture 25 Notice how blossoming simplifies the analysis of Bezier curves by providing natural labels for all the interior nodes in the de Casteljau algorithm Blossoming is a beautiful powerful clever almost magical idea 4 Differentiation and the Homogeneous Blossom Points along polynomial curves can be represented in terms of the blossom by invoking the diagonal property But what about derivatives Curves take on values that are points in affine space so too does the blossom Indeed only affine combinations of blossom values are permitted But derivatives represent tangent vectors not points To represent derivatives we need a variant of the blossom that takes on values in a vector space rather than an af ne space Here we shall construct such a blossom by applying the technique of homogenization Homogenization lifts the domain and the range from an af ne space to a vector space so we are no longer restricted to af ne combinations but can exploit instead arbitrary linear combinations 41 Homogenization and the Homogeneous Blossom Monomials are the simplest polynomials If Pt t then Pc t cnt c Pt Monomials are not linear Pc t 0 Pt but Pc t c Pt is almost as good On the other hand if Pt ant a0 11 gt 1 then Pc t c Pt because different terms have different degrees The key idea behind homogenization is to introduce a new variable to homogenize the polynomial so that all the terms have the same degree To homogenize a degree n polynomial Pt Ekaktk we multiply each term tk by w k Homogenization creates a new polynomial in two variables Ptw 2k aktkw k which is homogeneous of degree n that is each term has the same total degree 11 Therefore Pctcwc Ptw We can easily recover Pt from Ptw because Pt PLl Constructing Ptw from Pt is called homogenization recovering Pt from Ptw is called dehomogenization To homogenize the blossom pu1 u we homogenize with respect to each variable independently Thus the homogeneous version of 17041 u is another polynomial pu1v1 u v that is homogeneous with respect to each pair of variables ukvk In every term of pu1 u each variable uk appears to at most the first power so every term of the homogeneous polynomial pu1v1 u v has as a factor either uk or vk but not both Since pu1 v1 u v is homogeneous of degree one in each pair of variables ukvk 19u1v1Cukvkunv cpu1v1 ukvkunvn Again we can dehomogenize pu1v1 u v by setting vk 1 k n Thus pu11un1 pu1u We can also blossom the homogenization of P t We define the blossom of a homogeneous polynomial Ptw to be the unique symmetric multilinear polynomial pu1v1 u v that reduces to Ptw along the diagonal Thus the homogeneous blossom satisfies the following axioms Homogeneous Blossoming Axioms i Symmetry 19u1v1ukvkunv pua1va1ua va for every permutation c7 of 1n ii Multilinear pulv1ukvk rkskunv pu1v1ukvkunvnpu1v1rkskuv pulv1cukvkunv cpu1v1ukvkunvn iii Diagonal ptwtw Pt w Geometrically the variables tu1u represent parameters in a 1 dimensional affine space The homogenizing parameters wv1v play the role of mass lifting the variable tu1u from a 1 dimensional affine space to a 2 dimensional vector space where we can perform linear algebra Thus in the homogeneous blossom we have replaced the multiaffine property by the multilinear property pulv1ukvkrkskunv pu1v1 ukvkuvpu1 v1 rkskuv pulv1Cukvkunv cpu1v1 ukvkunvn This property is equivalent to the fact that for each parameter pair uivi either ul or v1 but not both appear in each term to the first power see Exercise 5 Now starting with any polynomial Pt we can blossom and then homogenize or we homogenize and then blossom Figure 4 illustrates how this works in practice for the monomials Lt t2 t3 considered as cubic polynomials Notice that if we blossom and then homogenize we get the same result as when we homogenize and then blossom We formalize this result in Theorem 6 Pt1 M P 12 22 31 homo genize homogenize bl Ptw w3 M P 12V12 22V22 32 V1V2V3 9 blossom u u u Ptt gt nu1u2u3 homogenize homogenize 2 blossom u1v2v3 u2v3v1 u3v1v2 Plttaw tw gt pu1V1u2V2u3V3 f 2 blossom uluz 142143 143141 Ptt gt pu1u2u3f homogenize homogenize blossom u1u2V3 u2u3v1 u3u1v2 PltWgt t2 W gt pltu1v1gtltu2v2gtltu3v3gt 3 3 blossom Ptt gt P 12 22 3 1142143 homogenize homogenize 3 bl Ptw t 03mm pulv1u2v2 M3V3 141142143 Figure 4 Blossoming and homogenizing the monomials Lt t2 t3 Observe that blossoming and homogenization commute Theorem 6 Blossoming and homogenization commute Proof This result follows immediately from Figure 5 since it is straightforward to verify that the functions in the right hand column are symmetric multiaff1ne on top multilinear on bottom and reduce to the corresponding functions in the left hand column along the diagonal blossom Ekckog k Ekckguil quot quotik homogenize homogenize blossom Ek0kgtkwnk gt Ekckzuhmuikvikn quotivin Figure 5 Blossoming and homogenization commute The inner sum on the right hand side is taken over all subsets i1 ik of 1 n Notice that Figure 5 also establishes the existence of the homogeneous blossom since the expression in the lower right hand corner of the diagram is symmetric multilinear and reduces to the expression on the bottom left along the diagonal Uniqueness follows from dehomogenization if we dehomogenize the homogeneous blossom then we get the multiaffine blossom Since the multiaffine blossom is unique rehomogenization shows that the homogeneous blossom is also unique We constructed the multiaffine blossom in Figure 3 by blossoming the de Casteljau algorithm replacing tby a different parameter uk on the kth level of the algorithm We can do the same for the multilinear blossom Begin by homogenizing the de Casteljau algorithm This amounts to replacing b t gt bw t and t a gt t aw to insure that each term has the same total degree see Figure 6 To blossom we now replace the pair tw by the pair ukvk on kth level of the algorithm see Figure 7 This process generates a symmetric multilinear function that reduces to the homogeneous curve when we replace each pair uk vk by tw This function is multilinear rather than multiaffine because it is linear in ukvk on the kth level of the algorithm Thus uk or vk but not both appears in every term to the first power Notice by the way that if we blossom first and then homogenize we get exactly the same diagram Blossoming first gives us Figure 3 homogenizing this diagram generates Figure 7 We illustrate all four variants of the de Casteljau algorithm original blossomed homogenized and blossomed and homogenized in Figure 8 if bw V t aw aff bff bw Raw bw t aw aaf bf bbf bW f aw bw aw 17147 yaw a aab abb bbb Figure 6 The homogeneous version of the de Casteljau algorithm for cubic Bezier curves This diagram is generated from the de Casteljau algorithm Figure 1 by replacing b t gt bw t and t a gt t aw along the edges of the triangle Here we use to denote homogeneous values so f tw while a a1 Notice that t aw b a bw t 1 b a a t w b 1 Therefore by the linearity of the homogenous blossom pabfpabbw ta b bwtpaba tawpabb b a b a b a b a and similar identities hold at all the other nodes in this diagram 111112113 bV3 3 V 6W3 39113922 17121112 bv u bvz quot 2 2 2 2 12 uz dvz mull 17111 1212121 bv u 17 b 1 1 1 1 V1 VM avl ulavl VWl a aab abb bbb Figure 7 The homogeneous blossom of a cubic Bezier curve This diagram is generated by blossoming the homogeneous version of the de Casteljau algorithm Figure 6 that is by replacing the pair tw with the pair ukvk on kth level of the algorithm This diagram can also be generated from the multiaffine blossom Figure 3 by homogenizing the functions along the edges Thus once again we see that blossoming and then homogenizing is equivalent to homogenizing and then blossoming As in Figure 6 we use to denote homogeneous values so 11 M v while a a1 Notice that u av 171 ba b w Maw 17 a Therefore by the linearity of the homogenous blossom pahpab ul avl p aba bvl ul quotu1 avlhbv1 u1 b a b a a 1 d and similar identities hold at all the other nodes in this diagram 61 b b i ttt ulu 2n 3 all t7 b7 7 a blossom 3 3 a bit auluz bUIUZ V b V k3 by we aat b bl aaul 21bu1 bbul V39V V V VVV V 9 a aab I abb bbb Ma aab abb bbb i 2121 homogenize homogenize mm fut bwit tiaw bv37u3 113iav3 blossom all 1 mm aul uzquot bufuzquot bwit Kw by aw MTV Va 13er Van MN 3131 bbt aauf abu l bbulquot by Kw by w by WW bvly lebvru favlbvy favl 32121 Mb abb bbb aaa aab abb bbb Figure 8 Four versions of the de Casteljau algorithm for cubic Bezier curves the standard version upper left the homogeneous version lower left the blossomed version upper right and the homogeneous blossom lower right Blossoming and homogenization commute since we get the same result by traversing right and then down or down and then right Here we use to denote homogeneous values so t t w and 14 uv whereas a 611 and b 171 42 Differentiating the de Casteljau Algorithm We built the homogeneous blossom to deal specifically with differentiation We are now going to use a variant of Taylor s theorem along with the binomial expansion of the homogenous blossom to derive a formula for the derivatives of a polynomial in terms of the values of its homogeneous blossom Theorem 7 Taylor 3 Theorem Let P t be a polynomial of degree n Then I PUC t Pth 2 hk 41 k0 k Proof Recall from calculus that the standard version of Taylor s theorem is 13 P r 2 P r n Px PtPtx t 239 x t Tx t Setting x t h yields I n n Pth Pt P th P2 hz P h tiff n We can also compute Pt h using the diagonal property of the homogeneous blossom Let t t1 and 6 10 Then th Et h1 t1 h10 th6 Therefore by the diagonal property of the homogeneous blossom Pt h pt h5t ho We can expand pt h5 t ho by the multilinear property to get a formula for pt h5 t ho similar in form to the binomial theorem Theorem 8 Binomial Expansion Let pu1 mun be a symmetric multia inefunetion Then n n k pt h6t ha 1200 ptt55h 42 n V where t t1 and 6 10 Proof The proof is aninductive argument similar to the inductive proof of the binomial theorem We illustrate the case n 2 and leave the general case as an exercise see Exercise 8 To prove the result for n 2 just expand by lineaiity pt h5t h6 ptt ho ph6t h6 pt t pth6 ph6 t ph6h6 pt t 2pth5 ph6 ho pt 0 2pt6h p56h2 5 Theorem 9 Let P be apolynomial ofdegree n and letp be the homogenous blossom ofP Then 1 PM n prr66 43 n k J Wk where t t1 and 6 10 Proof By the diagonal property of the homogeneous blossom Pth pt h5t ha and this equality is valid for all values of h Comparing the coef cients of hk in Equation 41 14 and Equation 42 for Pt h and pt 115 t hi5 yields If k PU r n pamt I n kgt Thus to find the kth derivative of a polynomial Pt we need only compute the blossom value ptkt66 and mult1ply by a constant But we have already shown that by blossormng and n homogenizing the de Casteljau algorithm we can compute the homogenous blossom pl11v1l1nvn for any values of the parameters I11V1I1nvn see Figure 7 We illustrate the algorithms for computing ptt6 and ptt66 in Figures 910 Notice that if we homogenize the de Casteljau algorithm and then we replace t w gt 10 on any level of the de Casteljau algorithm the effect is to replace b w t gt 1 and t aw gt 1 that is the effect is to differentiate one level of the de Casteljau algorithm Now if we replace t w gt t1 on the remaining levels of the algorithm that is if we dehomogenize the remaining levels then up to a constant multiple we get the derivative of the original Bezier curve see Figure 9 If on klevels of the homogeneous de Casteljau algorithm we replace tw gt 10 and on the remaining n k levels we replace tw gt t1 then up to a constant multiple we obtain the kth derivative of the original Bezier curve This algorithm is precisely the derivative algorithm we introduced in Lecture 24 Blossoming provides an alternative proof as well as a more general algorithm n5 2 2 a MS bus 7 K V Xa 1115 1115 bbd 739 739 7 m aab abb 22222 Figure 9 The first derivative of a cubic Bezier curve Compare to Figure 7 with M1510a11d142v2M3V3t1 15 n35 b t X a add 766 39 7 m6 1176 bb a dab abb bbb Figure 10 The second derivative of a cubic Bezier curve Compare to Figure 7 with u1v1 u2v2 5 10 and M3V3 t1 43 Conversion Algorithms Between Monomial and Bezier Form We can also use blossoming to develop algorithms to convert between monomial and Bezier forrn That is given the monomial coefficients of a polynomial we can find the Bezier control points and conversely given the Bezier control points we can find the monomial coefficients The key observation here is that the monomial coefficients are derivatives at least up to constant multiples and we have just seen that derivatives can be represented at least up to constant multiples by values of the homogeneous blossom To see the connection between monomial coefficients derivatives and blossom values suppose Pt a0 a1t 6ka ant Recall that by Taylor s theorem I Pk 0 P 0 Pt P0P0ttkm n Comparing the coef cients of tk and invoking Theorem 9 yields P00 0 n ak k kp0056 k0n 44 n k k or equivalently k p0055 n k k k where 5 10 Equation 44 is reminiscent of Equation 31 for the interval 01 PkPQI0L1 k0n W k 16 which gives the Bezier control points of Pt over the interval 01 Thus to convert between monomial and Bezier form we need only convert from one set of blossom values to another We illustrate these conversion algorithms for cubic curves in Figure 11 these algorithms generalize to arbitrary degree in the obvious manner Notice that to convert between monomial and Bezier form the monomial coefficients must be normalized by multiplying or dividing by binomial coefficients 666 111 Monomial Bezier Coef CientS 066 155 Control Points 011 116 7W 7 f 7 N 006 016 116 001 016 155 000 001 011 111 000 006 055 666 Bezier Contr01 POintS Monomial Coefficients a Bezier to Monomial Form b Monomial to Bezier Form Figure 11 Conversion between cubic Bezier and cubic monomial form In a we convert from Bezier to monomial form in b we convert from monomial to Bezier form Notice that the labels along the edges in these diagrams do not need to be normalized because 1 11 0 1 10 0 5 Thus we subtract at each node to get from Bezier control points to monomial coefficients and we add at each node to get from monomial coefficients to Bezier control points These algorithms work in arbitrary degree Notice that the diagram for the algorithm to covert from Bezier to monomial form is the same as the diagram for the algorithm to compute the nth derivative of a Bezier curve over the interval 01 5 Summary Blossoming is a potent tool for deriving properties of Bezier curves In this lecture we applied blossoming to derive the de Casteljau subdivision algorithm and the de Casteljau differentiation algorithm for Bezier curves as well as algorithms to convert between monomial and Bezier form B splines can also be conveniently investigated from the perspective of blossoming we shall investigate B splines in our next lecture Blossoming is related to Bezier curves because each node in the de Casteljau algorithm has an interpretation in terms of a blossom value There are also several important variants of the de Casteljau algorithm that can be generated by straightforward substitutions 17 Blossoming t gt uk on the kth level Homogenization t a gt t aw b t bw t onevery level Di erentialion kth derivative t a gt 1 n on k levels and multiply the output by b t gt 1 n k We illustrate the blossoming interpretation of the de Casteljau algorithm along with these three variants of the de Casteljau algorithm for cubic Bezier curves in Figure 12 15 As usual we use the multiplicative notation uvw to represent the blossom value pu v w Figure 12 The de Casteljau evaluation algorithm for cubic Bezier curves with each node interpreted as a blossom value WW3 b V y a auluz bum W V a 739 v a abui bbu aaul 1 l7 b u ltabyya 7 Wm M aab abb bbb Figure 13 The blossomed version of the de Casteljau algorithm for cubic Bezier curves 18 an bf bW Kaw bW F aW of ab bb WV KW lm aw by yaw 100 abb Figure 14 The homogeneous version of the de Casteljau algorithm for cubic Bezier curves ttw m5 b t a 1116 bid 17 V1 27 ya aa 1176 bb 7 7 7 a aab abb bbb Figure 15 The differentiated version of the de Casteljau algorithm for cubic Bezier curves 6 10 We close with a summary of the primary properties of the blossom The first three properties are the blossoming axioms the three properties that uniquely characterize the blossom Property iv is the key connection between blossoming and Bezier curves and Property v is the connection between blossoming and differentiation Primary Progerties of the Blossom i Symmetry pu1u pua1uan forevery permutation c7 of 1n ii Multiaffine pu11 xukkaun1 xpu1ukuxpu1vku 19 ii39 H Diagonal Pt pt I 1 iv Dual Functional Pk paabb kth Bezier Control Point k k n v Di erentiation Pkt 55 5 10 k n ptt quot40 71 Exercises 1 Let Pt and Qt be polynomials of degree n Prove that a If Rt Pt Qt then ru1 u pu1 u qu1 u b If St cP t then su1u cpu1u 2 Let Pt t a Show that pu1u ul au a U af 3 Let 3 l ljktj tk H k and let Pt EPkna k Using the result of k0 Exercise 2 show that RC pt0 tk1tk1 t 4 Let p041 u be a polynomial in which each variable appears to at most the first power Show that pu1 u is multiaf ne 5 Let pu1v1 u v be a polynomial in which either uk or vk but not both appears in every term to the rst power for k n Show that pu1 v1 unv is multilinear 6 Let ulnu denote the polynomial ul tu I Show that with this interpretation the algorithms represented by Figures 1 and 3 remain valid 7 Let Ptw and Qt w be two homogeneous polynomials of degree n Show that Pct cw Ptw Qctcw Qtw b Ptw w Pt w1 20 8 In this exercise you will complete the proof of Theorem 8 a Use induction to prove the binomial theorem I l a b 2 gakb k k0 b Mimic the inductive proof of the binomial theorem in part a to prove that n k pth5th6 2 gm 66h k0 ll 1 W4 n k k 9 Let Pt be a polynomial of degree 11 over the interval 6117 with Bernstein coefficients P0P Let GP t tPt denote the graph of the polynomial Pt Show that the Bezier control points of GP I over the interval 61 b are given by Qk akb a n Pk k0n 10 Let M130 a t ak k denote the monomial basis at x a Develop algorithms to convert between a the monomial basis at x a and the Bernstein basis over the interval 61 b b the monomial basis at x 0 and the monomial basis at x a c the Bernstein basis over the interval 61 b and the monomial basis at x 0 11 Using the results of Exercises 9100 and the intersection algorithm for Bezier curves in Lecture 25 Section 31 develop an algorithm for finding the roots of a polynomial lying in the interval a b 12 Let B t denote the Bernstein basis functions over the interval 61 b and let Lt c t d be a linear function a Using the dual functional property show that i 3051 k0 n k 11 E a b a Bk Oat k0 1 b Using the result of part a show that n k n E Llta b aBkt a Lt k0 1 21 13 Let 330 denote the Bernstein basis functions over the interval 01 Using the dual functional property prove the following identities I l k a E BZt Edy J on k0 k n n b E 1 Bkts1 2t k0 0quot n n n 2 BnkxBktax t k0 k 14 Let P t be a Bezier curve of degree 11 over the interval 6L 1 Every polynomial of degree n is also a polynomial of degree n1 Let pnu1u denote the blossom of Pt as a polynomial of degree n and let pn1u1un1 denote the blossom of P t as a polynomial of degree n 1 In addition let P0P be the Bezier control points for Pt as a polynomial of degree n and let Q0 Qn1 be the Bezier control points for P t as a polynomial of degree n 1 Show that n1 Pn 1 k 12 k1va n0 a pn1u1mu1 E k1 n1 k n1 k b QkmPk1WPk k0n1 22 Lecture 13 Matrix 39 for Affine and Proiective Transformations thou shalt set apart unto the LORD all that openeth the matrix Exodus 13 12 1 Matrix Representations for Aff me Transformations In the previous lecture we derived formulas for affine and projective transformations using the techniques of vector geometry and vector algebra Formulas expressed in vector algebra are effective for computing individual transformations but these formulas are not ef cient for composing transformations Therefore in this lecture we are going to derive matrix representations for each of the classical transformations of Computer Graphics so that we will be able to compose these transformations by matrix multiplication To fix our notation denote the origin by 0 and the three unit vectors along the xyz coordinate axes by i jk Then in 3 dimensions for any vector v and any point P there are constants v1 v2 v3 and pl 172 p3 such that v v1iv2jv3k P0p1ip2jp3k The constants v1 v2 V3 and p1 p2 p3 are the rectangular coordinates of v and P and we often abuse notation and write v v1 v2 v3 and P pl 172 p3 Now letA be an affine transformation Then sinceA preserves linear and affine combinations Av v1A i v2 Aj V3 Ak AU 140 P1Ai P2 AU 173 AUC Thus if we know the value of A on the three vectors i j k and on the single point 0 then we know the value of A on every vector v and every point P that is any affine transformation A is completely determined by the four values A0 Ai A j Ak Since af ne transformations map points to points and vectors to vectors there are constants aij such that AU 11i 12 j 13 k 11 12 13 AU 21 i 22 1 23k 21 22 23 Mk 31 i 32 1 33k 312 322 33 A0 0 a41i a42 j a43 k a41 a42 a43 Therefore the 12 numbers aij completely characterize the af ne transformation A It seems natural then that we should represent A by a 4 X 3 matrix and write 14031 11 12 13 A AU 21 22 23 Mk 31 32 33 140 41 42 43 But there is something not quite right about this 4 X 3 matrix If we represent a transformation by a matrix then we expect that if we multiply the coordinates of a point or a vector by the matrix we should get the result of the transformation applied to the point or vector However points and vectors in 3 dimensions have only 3 coordinates whereas this matrix has 4 rows To resolve this inconsistency we shall introduce affine coordinates for points and vectors and 4X4 matrices to represent affine transformations Recall that in 2 dimensions we insert a third coordinate an affine coordinate for points and vectors the affine coordinate for points is 1 the affine coordinate for vectors is 0 This affine coordinate allows us to represent affine transformations in the plane by 3 X 3 matrices We shall follow similar conventions in 3 space in 3 dimensions we insert a fourth affine coordinate for points and for vectors Again the affine coordinate for points is 1 the affine coordinate for vectors is 0 Following this convention AU OW 11 12 13 0 A AU 0 21 22 23 0 11 Ak 0 31 32 33 0 A0 1 41 42 43 1 Now for vectors we have Ai 0W 140 VAiv A39v Ak v v v 0 AU 0 1 2 J 3 1 2 3 Ak 0 A0 1 or equivalently 11 12 13 01 a a a 0 Av v1v2V30 21 22 23 v0A 31 32 33 0 l 41 42 43 Similarly for pomts Ai 0 AP A0pAip Ajp Ak P p P 1 AU 0 1 2 3 1 2 3 Ak 0 A0 1 or equivalently 11 12 13 0 a a a AltPgt p1p2p31 21 22 23 P1A 31 32 33 0 41 42 43 1 In this way affine transformations are represented by multiplying the affine coordinates of points and vectors by special 4 X 4 matrices where the last column is always 0001T 2 Linear Transformation Matrices and Translation Vectors To derive explicit 4X4 matrix representations for all the standard transformations of 3 dimensional Computer Graphics translation rotation mirror image uniform and non uniform scaling and orthogonal and perspective projection we need to convert the corresponding formulas from vector algebra into matrix form To achieve this goal notice that the 4 X 4 matrix representing an affine transformation A always has the following form L 0 A A 21 WA 1 where L A is a 3 X 3 matrix and WA is a 3 dimensional vector Moreover for any vector v L A 0 Av v0 vLA0 22 WA 1 Thus the 3 X 3 matrix L A represents a linear transformation on vectors Similarly for any point P LA 0 AP P1 PLAwA1 23 WA 1 Thus the vector WA represents a translation vector Hence we can decompose A so that 3 X 3 LinearTransformation Matrix 0 LA 01 1 1 WA 1 Translation Vector 1 Our goal is to find explicit expressions for the matrix LA and the vector WA for each of the A standard affine transformations of 3 dimensional Computer Graphics 21 Linear Transformation Matrices Let us begin with the 3 X 3 matrix L A Looking at the formulas for affine transformations from the previous lecture we see that on vectors these formulas all have the following form Av vnew 01v 02v39 1012 03MX v where u 12 are fixed unit direction vectors and 010203 are constants To represent these linear transformations using matrices we introduce the following three 3 X 3 matrices 3 1 0 0 I 0 l 0 3X3 Identity Matrix 25 L0 0 1i 1 13911 13912 13913 T391 3912 3913 42741 23972 23911 26 33911 33972 33913 0 M3 u2 u X u3 0 M1 27 L 2 ul 0 J It follows easily by direct computation from Equations 25 26 27 that vIv vgtlltuT 11 vuT12 v39u12 vugtltugtltv Thus I represents the identity transformation uT 12 represents the dot product with u or parallel projection onto u when 12 u and u X represents the cross product with u Hence clvczv 39u1203ugtltv vcll 02 uT 03ugtlt 28 Therefore using Equation 28 we can easily find the matrix representing the linear transformations L A mechanically in the following manner Av clvczv 39u1203ugtltv l l l l 29 LA011 czuT 11 c3ugtlt 22 Translation Vectors To find the translation vector WA observe that each of the affine transformations A from the previous lecture except for translation has a fixed point Q that is a point Q for which AQ Q Now for any point P P Q P Q Therefore since A is an affine transformation AP AQ AP Q Q AP Q 210 Moreover since P Q is a vector we know from Section 21 that AP Q P QLA PLA QLA 211 Hence by Equations 210 and 2 11 AP QPLA QLA PLAQI LA 212 4 But by Equation 23 APPLAwA 213 Therefore we conclude from Equations 212 and 213 that WAQI LA 214 where Q is any xed point of the affine transformation A With Equations 29 and 214 for LA and WA in hand we are now ready to derive matrix representations for each of the standard transformations of 3 dimensional Computer Graphics 3 Rigid Motions Rigid motions in 3 dimensions are composites of three basic transformations translation rotation and mirror image 31 Translation Let w be a translation vector For any point P and any vector v v v v I PM Pw PIw Therefore the matrix Transw representing translations is simply Transw 1 3 1 w Example 31 The matrix representing translation parallel to the x axis by the distance d is given by 1 0 0 0W I 0 0 1 0 0 Transd i d1 1 0 0 1 0 d 0 0 1 Similarly the matrices representing translation parallel to they or z axes by the distance d are given by 1 0 0 0W 1 0 0 0W 0 1 0 0 0 1 0 0 Transd j and Transd k 0 0 1 0 0 0 1 0 0 d 0 1 0 0 d 1 32 Rotation Let L be an axis of rotation defined by specifying a point Q on L and a unit direction vector u parallel to L and let 0 be the angle of rotation Denote by R0tQu0 the 4 X 4 matrix representing rotation of points around the line L through the angle 0 and denote by R0tu0 the upper 3X3 submatrix of R0tQu0 Then by Equation 214 since Q remains fixed under rotation 32 R0tu 0 0 R0tQu 9 QI R0tu0 1 Moreover by the Formula of Rodrigues see Lecture 12 Section 62 for any vectorv v new cos 0v 1 cos 6v 39 uu sin 0u X v Therefore we can nd R0tu 0 by invoking Equation 29 v new cos 0v 1 cos0v 39 uu sin0u X v 1 l l l 33 R0tu 0 cos 1 1 cos 0uT u sin 0u X Thus by Equations 25 26 27 cos0 1 cos 0u12 1 cos 0u1u2 sin 0 M3 1 cos 6u1u3 sin uz R0tu 0 1 cos 6u1u2 sin 0 M3 cos 0 1 cos0 14 1 cos0 142143 sin 0 M1 1 cos0 141143 sin 0 uz 1 cos 0 2 M3 sine M1 cos0 1 cos 0u32 34 Example 32 Suppose that the axis of rotation is the z axis Then we can choose Q Origin 000 and u k 001 Now by Equation 33 R0tk 0 cos0I 1 cos0kT k sin0k X 35 But by Equations 26 and 27 0 0 0W 0 1 0W kTgtxltk L0 0 OJ and kX L 1 0 0 0 0 1 Therefore cos 0 sin 0 0 R0tk 0 sin0 cos 0 0 L 0 0 1J Hence the matrix R0t0rigink0 representing rotation around the z axis by the angle 0 is given by cos 0 sin 0 0 0 sin 0 cos 0 0 0 0 0 1 0 39 0 0 0 1 R0t0rigin k 0 R0tk0 0 OriginI Rotk0 1 Similarly the matrices representing rotation around the x and y axes by the angle 0 are given by 1 0 0 0 0 cos 0 sin 0 0 0 sin 0 cos 0 0 0 0 0 1 R0t0rigin i 0 and cos 0 0 sin 0 0 1 0 0 R0t0rlgm0 Sing 0 COS 9 0 0 0 0 1 33 Mirror Image Let S be a mirror plane speci ed by a point Q on S and a unit vector 11 normal to S Denote by MirQ n the 4 X 4 matrix representing the mirror image of points in the plane S and denote by Mirn the upper 3X 3 submatrix of MirQn Then by Equation 214 since Q remains xed under mirror image MirQn Mir 0 36 QI ern 1 Moreover for mirror image see Lecture 12 Section 62 vnewv 2v39nn Therefore we can nd Mir n by invoking Equation 29 vnew v 2v39 nn l l l 37 Mirn I 2nT n Now notice that 1 Mirn 2nT n so QI Mirn Q2nT n 2Q nn Therefore by Equations 36 and 37 MirQn 1 38 Example 33 Suppose that the mirror plane is the xy plane Then we can choose Q Origin 000 and n k 001 By Equations 26 0 0 0W kTgtxltk 0 0 0 i0 0 1i Therefore 1 0 0 0W 1 2kT k 0 0 1 0 0 Mir0rigink 20rigin39nn 1 0 0 1 0 0 0 0 1 Similarly the matrices representing mirror images in the xz plane and yz plane are 100 1000W M0 0100 d MW 100 If r1 m an lr r1 1111 g 0010 g 0010 0001 0001 4Scaling We are interested in both uniform and non uniform scaling 41 Uniform Scaling Uniform scaling is defined by specifying a point Q from which to scale distance and a scale factor 3 For any point P and any vector v see Lecture 12 Section 62 new v sv v SI PMw sP1 sQ P sI1 sQ Therefore the matrix ScaleQ 3 representing uniforrn scaling about the point Q by the scale factor 3 is given by S l SI 0 41 caeQs 1 SQ 1 Example 41 To scale uniformly about the origin by the scale factor 3 set Q Origin 000 Then by Equation 41 s 0 0 0W SI 0 0 s 0 0 scaldongms 1 s0rigin 1 0 0 0 39 0 0 0 1 42 NonUniform Scaling Non uniform scaling is defined by designating a unit vector u specifying the scaling direction as well as a point Q about which to scale and a scale factor 3 Denote by ScaleQ u s the 4 X 4 matrix representing non uniform scaling from the point Q in the direction u by the scale factor 3 and denote by Scaleus the upper 3X3 submatrix of ScaleQ u s Then by Equation 214 since Q remains fixed under this scaling Scaleus 0 ScaleQ 143 Q I scald S 1 42 Moreover for non uniform scaling see Lecture 12 Section 62 vnew v s 1v 39 uu Therefore we can find Scaleu s by invoking Equation 29 vnew v s 1v 39 uu l l l 43 Scaleus Is 1uT u Now notice that I Scaleus 1 s uT u so Q I Scaleus 1 sQ uT u 1 sQ uu Therefore by Equations 42 and 43 SCCMQMS IS 1uTu 0 44 1 sQ 39 uu 1 Example 42 To scale about the origin in the direction of the z axis by the scale factor 3 we can choose Q Origin 000 and u k 001 By Equations 26 0 0 0W kTgtxltk 0 0 0 lo 0 11 Therefore by Equation 44 1 0 0 0W Is 1kTk 0 0 1 0 0 Scale0rlgmks 1 s0rigin 39 k k 1 0 0 s 0 0 0 0 1 Similarly the matrices representing scaling about the origin along thex and y axes are 9 s 0 0 0 1 0 0 0W Scale0riginis 0 1 0 0 and Scale0riginjs 0 S 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 5 Projections Orthogonal projection is an affine transformation but perspective projection is not affine Therefore in this section we will be concerned only with orthogonal projections Parallel projections projections into a fixed plane parallel to a fixed direction are also affine These projections are covered in Exercise 2 P I 39 39 quot will be 39 1 J I in detail in Section 6 51 Orthogonal Projection Let the plane S into which points are projected be defined by a point Q and a unit normal vector n and denote by 0rthQn the 4X 4 matrix representing orthogonal projection into the plane S The formulas for orthogonal projection are see Lecture 12 Section 62 vnewv v39nn PW P P Q39nn Notice that these formulas are almost exactly the same as the formulas for mirror image except for the missing factors of 2 Therefore using the same analysis we used for mirror image we arrive at I nT n 0 51 Q39nn 1 0rth0Qn which is the same matrix as MirQ n in Equation 38 except for the missing factors of 2 Example 51 Suppose that the projection plane is the xy plane Then we can choose Q Origin 000 and n k 001 By Equations 26 0 0 0W kTgtxltk 0 0 0 lo 0 ll Orth00rigin k Therefore 1 kT k 0 Origin 39 nn 1 OOHO 0000 Ho Similarly the matrices representing orthogonal projections into the xz plane and yz plane are 1 0 0 0 0 0 0 0 0 0 0 0 0rtho0rlgln 0 0 1 0 and 0rtho0rlglnl 0 1 0 0 0 0 1 0 0 0 1 6 Perspective Unlike all of the other transformations that we have investigated so far perspective projection is not an affine transformation because perspective projection is not a well defined transformation at every point nor is perspective well defined for any vector Nevertheless we shall see shortly that we can still represent perspective projections by 4 X 4 matrices 61 Projective Transformations and Homogeneous Coordinates Perspective projection is defined by specifying an eye point E 818283 and a plane S into which to project the image The plane S is specified as usual by a point Q 611612613 on S and a unit vector n n1 n2 n3 normal to S The image of an arbitrary point P xyz under perspective projection from the eye point E 81 8283 to the plane S is given by the expression see Lecture 12 Section 62 new E Q39nPQP39nE E P n or in terms of coordinates xnew 31 611quot132 612quot2 33 13quot3x W1 P1quot1 Wz P2quot2 W3 P3quot331 P 61 111X 112y 1132 81111 82112 83113 ynew 31 611quot132 612quot2 33 613quot3y W1 P1quot1 Wz P2quot2 W3 P3quot332 111X 112y 1132 81111 82112 83113 Znew 31 611quot132 612quot2 33 613quot3Z W1 P1 quot1 W2 P2quot2 W3 P3quot333 111X 112y 113Z 81111 82112 83113 Notice that since the point P appears in both the numerator and the denominator on the right hand side of Equation 61 the variables x yz appear in both the numerator and the denominator of the 118W 118W 118W y 2 numerator and the denominator are called projective transformations In order to represent expressions for the coordinates x Transformations where x yz appear in both the perspective projection by matrix multiplication we need to be able to represent projective transformations using matrix multiplication So far we can only invoke matrices to represent linear and affine transformations 1 1 Linear transformations are transformations of the form new x a x a a z 11 21y 31 all a12 a13 new y 129 22y 32Z ltgt 5 y Z k 21 22 23J 1 a13x a23y d33Z 31 32 33 Linear transformations are readily represented by 3 X 3 matrices because matrix multiplication with rectangular coordinates generates 3 linear functions in the coordinates Affine transformations are transformations of the form xnew a11x a21y 312 a41 11 12 13 0W ne 21 22 23 0 a y W a12xa22y a322a42 ltgt x y z 1 a I32 I33 0 new 1 a x a y a z a 13 23 33 43 41 42 43 1 Affine transformations cannot be represented by 3 X 3 matrices because matrix multiplication with rectangular coordinates cannot capture the constant translation terms To represent affine transformations by matrices we introduced affine coordinates for points and special 4 X 4 matrices where the last column is 0 0 0 1T in order to capture the constant translation terms Projective transformations are transformations of the form 1436 d24y d34Z I44 xnew 1195 21y 31Z 41 new 1236 zzy 322 I42 1436 d24y d34Z I44 Znew 1395 23y 33Z 43 1436 d24y d34Z I44 Projective transformations cannot be represented by either 3 X 3 or 4X 4 matrices because matrix multiplication with either rectangular or affine coordinates cannot capture denominators To represent projective transformations using matrices we need to introduce a new device in order to express rational linear functions using matrix multiplication The device we shall adopt is called homogeneous coordinates an extension of affine coordinates designed specifically to handle common denominators So far we have permitted the fourth coordinate to be only 0 or 1 now we shall permit the fourth coordinate the homogenous coordinate to take on arbitrary values By convention if w 0 then the four homogeneous coordinates x yz w represent the point with rectangular coordinates x w y w z w that is denominators are stored in the fourth coordinate 12 We can now express projective transformations by 4 equations in the homogeneous coordinates x yz w new 96 11x 21y 31Z 41 all an 6413 6114 ll EW Y 1295 22y 32Z 42 21 2 23 24 a ltgt x y z 1 2 algx dzgy 64332 6443 31 32 33 34 n 41 42 43 44 w M a14x a24y a34z 44 Thus using homogeneous coordinates we can represent projective transformations by arbitrary 4X4 matrices where the last column captures the denominator Another advantage of homogeneous coordinates is that we can postpone division until we actually need a numerical result 62 Matrices for Perspective Projections Let us return now to perspective projection Recall that the formula for perspective is Pnew E Q39nP QP39nE E P 39 n where E is the eye point and S is the projection plane specified by a point Q on S and a unit vector 11 normal to S Using homogenous coordinates we can place the denominator in the fourth coordinate and write PW E QnPQ PnE E Pn 62 Expanding the terms on the right hand side of Equation 62 gives PW E QnP P 39nE Q39nE P 39n E 63 Now observe that E Q 39nP P E Q n1 P 39nE PnT E PnT E Therefore by Equations 63 and 64 the numerator of Pnew is 64 E Q39nP P39nEQ39nE PE Q39nI nT EQ39nE new Moreover the denominator of P is P39nE39nP nTE39n Therefore it follows that E Q 39nI nT E nT P39WJ P1 Q39nE E39n Thus with the convention that the fourth coordinate represents the denominator the 4X 4 matrix PerspE Qn representing perspective projection from the eye point E to the plane S is given by 13 E Q39nI nT E nT P E ersp Qn QWOE E 65 Example 61 Suppose that the eye is located along the z axis at E 001 and perspective plane is the xy plane Then we can choose Q Origin 000 and n k 001 By Equations 26 oooj kTgtxltE 000 L001 Therefore by Equation 65 1 0 0 0W E Oquot k1 kTE kT 010 0 PerspE0rigink rlgm Origin39kE E39k 0 0 0 1 0 0 0 1 Thus the projective transformation representing perspective projection into the xy plane is new new new new 8W ne 0 w x xy yz new0 1 z ltgt x x1 z y wy1 z z 7 Summary Below we summarize the main themes of this lecture Also listed below for your convenience are the matrix representations for each of the transformations that we have studied in this lecture 71 Matrix Representations for Af ne and Projective Transformations The core content of this lecture are 4X4 matrix representations for each of the basic affine and projective transformations translation rotation mirror image uniform and non uniform scaling and orthogonal and perspective projection of 3 dimensional Computer Graphics Every affine transformation A is completely determined by the four values A0 Ai A j Ak and these values form the rows of the matrix representation forA that is AG 0W AU 0 Ak 0 39 A0 1 Thus matrix representations for affine transformations all have the form A LA 0 3 X 3 Linear Transformation Matrix 0 WA 1 Translation Vector 1 14 The upper 3 X 3 matrix Ai 0W LA AU 0 iAk OJ can be constructed from three basic 3X3 matrices I uT 1 ux and the vector WA can typically be expressed in terms of a fixed point Q of the transformationA In particular vnewclvczv39u1203uxv gt LA 011 czuTf4 C3MX and WA QI LA Perspective projection is a projective transformation not an affine transformation Af ne transformations have the linear form xnewa11xa21ya312a41 11 12 13 0 a a a 0 ynew alzx any I322 42 ltgt x y z 1 21 2 23 31 new 32 33 0 z a x a y a z a 13 23 33 43 41 42 43 1 whereas projective transformations have the rational linear form xnew 1195 21y 31Z 41 a14x a24y a34z 44 11 12 13 14 new 1295 22y 32Z 42 a14x a24y a34z 644 32 33 34 new 13 23y 33Z 43 41 42 43 44 11426 a24y a34z 6144 a a a a ltgt x y Z1 21 2 23 24 a Z Perspective projections can still be represented by 4X 4 matrices but the last column is no longer 0001T instead the last column represents the common denominator To realize this representation we adopted a new 39 called 39 O quot for representing points in 3 dimensions By convention if w 0 then x z xyzW ltgt 1 w w w Thus the fourth coordinate the homogeneous coordinate represents a common denominator In the next lecture we shall look more closely at the intrinsic geometric meaning behind this formal algebraic convention 72 Matrices for Affine and Projective Transformations Translation by the vector w Transw 1 w Rotation around the line L determined by the point Q and the unit direction vector u by the angle 0 Rotu0 0 ROKQ M Q QI Rotu9 1 Rotu 0 cos 1 1 cos 0uT u sin 0u X Mirror Image in the plane S determined by the point Q and the unit normal n I 2 T 0 MirQn quot quot 2Q 39 nn 1 Uniform Scaling around the point Q by the scale factor 3 S l SI 0 caeQs 1 SQ 1 NonUniform Scaling around the point Q by the scale factor 3 in the direction u SeaMQ S Is 1uTu 0 quot 1 sQ39uu 1 Orthogonal Projection into the plane S determined by the point Q and the unit normal n I T 0 0rthoQ n n quot Q 39 nn 1 Perspective Projection from the eye pointE into the plane S determined by the point Q and the unit normal vector n E Q39nI nT E nT P E m Q n Q39nE E39n Exercises 1 Consider the shear transformation introduced in Lecture 12 Exercise 2 Let S Shearing plane 11 2 Unit vector perpendicular to S Q 2 Point on S u 2 Unit vector in S ie unit vector perpendicular to n Shear angle Recall that the formulas for shear are v new v tan v 39 nu PMWPmm mP Qynw a Show that the 4 X 4 matrix representing shear is given by 1 tan nT u 0 Shear n u Q tan Q 39 nu 1 b Suppose that i S is the xyplane ii u is the unit vector along the x axis iii 45 Write down the explicit entries of the 4 X 4 matrix ShearQn14 2 Recall from Lecture 12 Exercise 3 that parallel projection is projection onto a plane S along a direction u As usual the plane S is de ned by a point Q and a unit normal vector n Recall that the formulas for parallel projection are new V39quot v v u u39n PnewPP Q nu u39n a Show that the 4 X 4 matrix representing parallel projection is given by T I quot 0 PPr0jQnu 1439quot Q nu 1 run b Suppose that i S is the xyplane ii u is the unit vector parallel to the vector 111 Write down the explicit entries of the 4 X 4 matrix PPr0jQn u 17 Verify that a R0tu01 R0tu 0 R0tu 0T b Mirn 1 Mirn MirnT Verify that a DetR0tu 0 1 b DetMirn 1 Verify that a u is an eigenvector of R0tu 0 corresponding the the eigenvalue 1 b n is an eigenvector of Mir 11 corresponding the the eigenvalue 1 Interpret the results in parts ab geometrically The trace of a matrix is the sum of the diagonal entries Thus for a 3 X 3 matrix M TraceUW mm mzz m33 a Show that i TraceM N TraceM TraceN ii Tracec M c TraceUW b Using part a and Equation 33 conclude that cosw TraceR02t14 0 1 I Consider a rotation matrix R0tu 0 a Using Equation 33 or 34 show that we can recover the unit vector u parallel to the axis of rotation and the sine of the angle of rotation from the rotation matrix R0tu 0 by the formula 2sin6 u R0tu0213 Rommgyz Rotate1 Romans R0tu0112 R0tu0211 b Explain why we cannot solve independently for the axis of rotation u and the angle of rotation 0 Let M be a 3 X 3 matrix and let v w be arbitrary vectors a Show that vMwvwMT b Conclude from part a and Exercise 3 that i v R0tu 0 39 w R0tu 6 v 39 w ii v Mirn 39 w Mirn v 39 w c Interpret the results in part b geometrically 18 H H Let M be a 3 X 3 matrix and let v w be arbitrary vectors a Show that 14 M x w M DetMuXv M T b Conclude from part a and Exercises 34 that i v R0tu 0 X w 1 Ram 9 v X w ii v Mirn Xw Mirn v X w c Interpret the results in part b geometrically Let v1v2 be unit vectors and let u v1 sz a Show that the matrix uT u R0tuv139v2I uX 1 V1 39 V2 rotates the vector v1 into the vector v2 b Interpret this result geometrically Show that MirQ n ScaleQ n 1 Interpret this result geometrically Show that Mir n R0tn 7r Interpret this result geometrically Let 14x4 be the 4 X 4 identity matrix Show that on points 0rth0Q n 14x4 MirQn Let A be a nonsingular affine transformation Show that a A maps straight lines to straight lines b A preserves ratios of distances along straight lines that is if PQR are collinear then AR AP IR PI AQ AP IQ Pl39 Let T be a nonsingular projective transformation Show that a T maps straight lines to straight lines b Tdoes not necessarily preserve ratios of distances along straight lines That is give an example to show that if P QR are collinear then TR TP IR PI TQ TP I IQ Pl39 The cross ratio of four collinear points PQR S is defined by IR P S Q P Q R SF m Show that if Tis a projective transformation then Tpreserves cross ratios that is show that crTPTQ TR TS crP QR S 17 Let P be a point and let V1V2V3 be three linearly independent vectors in 3 space a 0 d Show that in 3 dimensions there is a unique affine transformationA that maps P v1 v2 V3 to Q W1W2W3 Show that if u is an arbitrary vector then A Detu v2 V3w1Detv1 u V3w2Detv1 v2 uW3 u Detv1 v2 V3 I Verify that the matrix representing this affine transformation A is given by 11 3111 01 v w 0 A 2 2 V3 0 W3 0 P 1 Q 1 Show that Equation 11 is a special case of the matrix in part c 18 Let P1P2P3P4 be four non collinear points in 3 space a O C Show that in 3 dimensions there is a unique affine transformationA that maps four non collinear points P1P2P3P4 to four arbitrary points Q1 Q2 Q3 Show that if R is an arbitrary point then R1 P11 P11 P11 Dth 1Q D R 1Q DtP2 1Q DtP2 1Q E E E 8 P311 P312 R 13 P314 1P4 1 1P4 1 1P4 1 KR 1 MR P 1 1 P 1 De 2 P31 P41 1 1V 1911 A Q P3 1 Q3 1 P4 1 Q 4 1 20 Programming Projects 1 The Turtle in 3Dimensions In two dimensions the turtle s state consists of a point P specifying her location and a vector u specifying both her heading and her step size To navigate in 3 dimensions the turtle carries around not just one vector u but three mutually orthogonal vectors uv w specifying her heading u her left hand v and her up direction w Thus in 3 dimensions the turtle carries around her own 3 dimensional local coordinate system The FORWARD and MOVE commands work much as before but in place of the TURN command there are three new turtle commands YAW PITCH and ROLL YAW represent a rotation in the av plane the plane perpendicular to the up direction w PITCH represents a rotation in the WM plane the plane perpendicular to the left hand vector v and PITCH represents a rotation in the vw plane the plane perpendicular to the forward direction a Also the RESIZE command is rede ned to apply simultaneously to all three turtle vectors instead of just one turtle vector Thus in 3 dimensions LOGO has the following commands FORWARD D and MOVE D Translation Pnew P D u YAWA Rotation in uv plane new u COSA V SinA unew COSA Sim4 gt1 Vnew u sinA v cosA vnew sinA cosA v PITCHA Rotation in wu plane wnew W COSA u SinA Wnew COSA sinA w gt1 anew w sinA u cosA sinA cosA new u ROLLA Rotation in vw plane Vnew v cosA w sinA vnew cosA sinA v gt1 wnew v sinA w cosA w sinA cosA new w RESIZE s Uniform Scaling 0 0y vnewsv ltgt vnew 0 3 0 v Wnew SW iwnewJ i0 0 SJ iWJ a Implement the 3 dimensional turtle in your favorite programming language using your favorite API Write LOGO programs to generate the edges of simple polyhedra in 3 dimensions Write recursive LOGO programs to create your own novel fractals in 3 dimensions 09 21 2 The Turtle on the Surface of a Sphere The classical turtle walks on the surface of an in nite plane But we could imagine that the turtle like us is actually walking on the surface of a large sphere In this environment when the turtle executes the command FORWARD D the turtle draws the arc of a great circle on the sphere The FORWARD and TURN commands correspond to different rotations of the sphere beneath the turtle or equivalently different rotations of the turtle in 3 space Since the turtle never leaves the surface of the sphere her position can be stored as a vector u of a fixed length from the center of the sphere Hence the turtle s state consist of two orthogonal vectors a position vector u of a xed length and a direction vector v perpendicular to the position vector u tangent to the surface of the sphere Thus for the turtle on the surface of a sphere LOGO consists of the following commands O FORWARD D and MOVE D Translation along the Sphere Rotation in the av Plane uu cosD Iv u sinD v DIV I u v ltgt newjujroltllvl v v sinD Iv I cosD Iv I vnew v XV u v TURN A Rotation Around the Vector u v Iv cosAv sinA ltgt vnew vroti A v luxvl lul RESIZES vnew Sv Implement LOGO on the surface of a sphere in your favorite programming language using your favorite API Write turtle programs to generate simple curves like polygons stars and spirals on the surface of a sphere Write recursive turtle programs to generate fractals on the surface of a sphere 3 CODO in 3Dimensions a 09 Implement CODO in 3 dimensions in your favorite programming language using your favorite API incorporating the 3 dimensional affine transformations discussed in the text and the exercises of this lecture Write CODO programs to generate the edges of simple polyhedra in 3 dimensions Develop iterated function systems to create fractals in 3 dimensions with and without condensation sets In particular develop iterated function systems to generate i 3 dimensional gaskets ii 3 dimensional snow akes iii 3 dimensional trees iv 3 dimensional fractals of your own novel design 22 4 Parser T a Let S g 3 1 denote the state of the 3 dimensional turtle see Project 1 Show that the LOGO commands for the 3 dimensional turtle can be implemented in the following fashion Command Exocentric TurtleCentric FORWARD D Snew S Tran3D u Snew TransD i S MOVE D Snew S TranAD u Snew TransD i S YAW A Snew SRotPw Iw A Snew Rot0riginkAS PITCHA Snew SRotPv Iv A Snew Rot0riginjAS ROLLA Snew SRotPuuA Snew Rot0riginiAS RESIZE s Snew S ScalePs Snew Scale0rigins S b Write a parser to convert recursive programs for the 3 dimensional turtle into iterated function systems that generate the same fractal c Give examples to illustrate the results of your parser 5 The 3Dimensional Turtle on a Bounded Domain The 3 dimensional turtle lives in an infinite space Suppose however that the 3 dimensional turtle is restricted to a finite domain bounded by walls When the turtle hits a wall she bounces off the wall so that her angle of incidence with the normal vector to the wall is equal to her angle of reflection and then she continues on her way see Lecture 2 Project 3 The Classical Turtle on a Bounded Domain To implement the 3 dimensional turtle on a bounded domain the FORWARD command must be replaced by NEWFORWARD D D1 Distance from Turtle to Wall in Direction of Turtle Heading IF D lt D1 FORWARD D OTHERWISE FORWARD D1 u v w T n x u ROTATE A Rot A A angle of re ection 0 0 0 In X ul NEWFORWARD D D1 Here n is the normal to the wall at the point of impact and cosA u n 23 a Implement LOGO on a bounded domain where the walls form i a rectangular box ii a sphere iii an ellipsoid U Consider the turtle program consisting of the single command NEWFORWARD D Investigate the curves generated by this program for different shape walls different values of D and different initial positions and headings for the turtle Investigate how curves drawn by the walled in turtle differ from curves drawn by the turtle in infinite space using the same turtle programs where FORWARD is replaced by NEWFORWARD O 6 The 3Dimensional Turtle in a 3Dimensional Manifold The 3 dimensional turtle lives in a flat 3 dimensional space Here we shall investigate turtles that live on curved 3 dimensional manifolds These manifolds can be modeled by rectangular boxes where pairs of opposite sides front and back left and right top and bottom are glued together possibly with a twist see Lecture 2 Project 5 The Turtle on 2Dimensional Manifolds for the analogous 2 manifolds modeled by rectangles When the turtle encounters a wall she does not bounce off the wall like the turtle on a bounded domain Project 5 rather she emerges on the opposite wall of the box heading in the same direction relative to the new wall in which she hit the opposing wall a Implement LOGO on one or more different 3 manifolds Note For each of these 3 manifolds you will need to define a command MFORWARD to replace of the command FORWARD in standard LOGO see Project 5 Consider the turtle program consisting of the single command MFORWARD D Investigate the curves generated by this program for different 3 manifolds different values of D and different initial positions and headings for the turtle Investigate how curves drawn by turtles on these 3 dimensional manifolds differ from curves drawn by the turtle in an infinite space using the same turtle programs where FORWARD is replaced by MFORWARD U 0 7 Linear Algebra Package for Computer Graphics Implement a basic linear algebra package for Computer Graphics Your package should include the following a Algebra of Points and Vectors Coordinate implementations for addition subtraction scalar multiplication dot product cross product and determinant b Affine and Projective Transformations 24 Matrix implementations for translation rotation mirror image uniform and non uniform scaling shear perspective projection and composite transformations c Distance Formulas Vector algebra implementations for the distance between two points a point and a line a point and a plane and two parallel or two skew lines Intersection Computations P Vector algebra implementations for the intersections of two lines two planes or three planes 8 Animation a Build a collection of 3 dimensional polyhedral models b Animate the models using the transformations developed in this lecture 25 19 Let Mw le M Aw U P P 20 14 Show that I uT w w X are all elements of Mw Show that the transformation matrices I uT w w X are linearly independent Show that i dimMw 6 ii din1span1uT w w X 5 Find an element of Mw not in spanIuT w w X Let M1M2 be two 4X 4 matrices and let MA 1 AM1 W2 Show that If M1 M2 represent affine transformations then M A is also represents an affine transformation If M1 M2 represent rotations then M A does not necessarily represent a rotation 26 Lecture 1 Turtle Graphics the turtle and the crane and the swallow observe the time of their coming Jeremiah 87 1 Turtle Graphics Motion generates geometry The turtle is a handy paradigm for investigating curves generated by motion Imagine a turtle that after each step leaves a trail connecting her previous location to her new location As this turtle crawls around on a at surface the turtle may traverse paths that form intriguing geometric patterns see Figure 1 Figure 1 Some interesting geometric patterns generated by turtle paths Some of you may have encountered this mythical turtle before in the programming language LOGO LOGO has been used in primary schools to introduce young children to programming but the turtle is more than just a toy for young children In their book Turtle Geometry Abelson and DiSessa use turtles to investigate many advanced topics ranging from elementary differential geometry and topology to Einstein s General Theory of Relativity The study of geometry using programming is the branch of Computer Science called Computational Geometry We shall begin our investigation of Computer Graphics with Turtle Graphics After developing a simple variant of LOGO we will see that Turtle Graphics can be used to generate many diverse shapes ranging from simple polygons to complex fractals 2 Turtle Commands To help understand the ideas behind Turtle Graphics we introduce a virtual turtle The virtual turtle is a simple creature she knows only where she is in which direction she is facing and her step size The virtual turtle obeys solely simple commands to change either her location or her heading or her notion of scale Consider such a virtual turtle living on a virtual plane The turtle s location can be represented by a point P a dot given by a pair of coordinates xy similarly the turtle s heading can be represented by a vector w an arrow given by another pair of coordinates u v see Figure 2 The step size of the turtle is simply the length of the vector w Thus the step size of the turtle is 2 2 le uv w P Figure 2 The virtual turtle is represented by a point P dot and a vector w arrow Location is a point direction is a vector Points are represented by dots vectors are represented by arrows Points have position but no direction or length vectors have direction and length but no fixed position In many branches of science and engineering the distinction between points and vectors is often overlooked but this distinction is very important in Computer Graphics We shall see shortly that computationally points and vectors are treated quite differently in LOGO The pair P w is called the turtle s state Although internally the computer stores the coordinates x y and uv the turtle and the turtle programmer has no access to these global coordinates the turtle knows only the local information P w not the global information 6 y and uv That is the turtle knows only that she is here at P facing there in the direction w she does not know how P and w are related to some global origin or coordinate axes to other heres and theres This state model for the turtle is similar to the model of a billiard ball in classical mechanics where physicists keep track of a ball39s position and momentum Turtle location is analogous to the position of the billiard ball and turtle direction is analogous to the momentum of the billiard ball The main difference between these two models is that for billiard balls the laws of physics differential equations govern the position and momentum of the ball in contrast we shall write our own programs to change the location and direction of the turtle The turtle responds to four basic commands FORWARD MOVE TURN and RESIZE These commands affect the turtle in the following ways FORWARD D The turtle moves forward D steps along a straight line from her current position in the direction of her current heading and draws a straight line from her initial position to her final position MOVE D Same as FORWARD D without drawing a line TURN A The turtle changes her heading by rotating her direction vector in the plane counterclockwise from her current heading by the an gleA RESIZE S The turtle changes the length of her step size direction vector by the factor S 2 These four turtle commands are implemented internally in the following fashion FORWARD D and MOVE D Translation see Figure 3 xnew x D u y new y D V TURN A Rotation see Figure 4 anew u cosA v sinA cosA sinA ltgt new Vnew u V vnew u s1nA v cosA s1nA cosA RESIZE S Scaling see Figure 5 u Su S 0 new ltgt new Vnewu V0 S vnewSv We shall also adopt the following conventions D lt 0 gt FORWARD D moves the turtle backwards A gt 0 gt TURN A rotates the turtle counterclockwise A lt 0 gt TURN A rotates the turtle clockwise S lt 0 gt RESIZE S rotates the turtle by 180 and then scales the direction vector by S Notice that the TURN and RESIZE commands can be implemented using matrix multiplication but that the FORWARD and MOVE commands cannot This distinction arises because rotation and scaling are linear transformations on vectors but translation is an affine not a linear transformation on points A point is not a vector so transformations on points are inherently different from transformations on vectors We shall discuss linear and affine transformations their precise meanings as well as their similarities and differences in detail in Lecture 4 The formulas for executing the four turtle commands can be derived easily from simple geometric arguments We illustrate the effect of each of these turtle commands in Figures 3 5 PM P Dw P Figure 3 The command FORWARD D changes the turtle s location but leaves her direction and step size unchanged The new turtle location is Pnew P D w Thus in terms of coordinates xnew x D u YnewyDV Wnew wL sina P w cosa W Figure 4 The command TURNa changes the turtle s heading but leaves her position and step size unchanged To derive the turtle s new heading we work in the turtle s local coordinate system Let P w be the turtle s current state and let wJ denote the vector perpendicular to w of the same length as w Then wnew w cosx wJ sinx But if w u v then wJ v u see Exercise 11 Therefore in terms of coordinates unew u cosx v sinx vnew v cosx u sinx or in matrix notation um vnewgtltu vgt sinx cosx cosx sina Figure 5 The command RESIZE S changes the turtle s step size by a factor of S but leaves her position and heading unchanged The turtle s new direction vector is given by wnew S w Thus in terms of coordinates unew S u vnew S v or in matrix notation um Vnewgtltu vgtS 0 os39 The turtle state P w is a complete description of what the turtle knows and the four turtle commands FORWARD MOVE TURN RESIZE are the only way that a programmer can communicate with the turtle Yet with this simple setup we can use the turtle to draw an amazing variety of interesting patterns in the plane 3 Turtle Programs Once the four turtle commands are implemented we can start to write turtle programs to generate a wide assortment of shapes The simplest programs just iterate various combinations of the FORWARD TURN and RESIZE commands For example by iterating the FORWARD and TURN commands we can create polygons and stars see Table 1 Notice that the angle in the TURN command is the exterior angle not the interior angle of the polygon Circles can be generated by building polygons with lots of sides Iterating FORWARD and RESIZE the turtle walks along a straight line and iterating TURN and RESIZE the turtle simply spins in place But by iterating FORWARD TURN and RESIZE the turtle can generate spiral curves see Figure 6 POLYGON N STAR N SPIRAL N A S REPEAT N TIlIES REPEAT N TIlIES REPEAT N TIMES FORWARD 1 FORWARD 1 FORWARD 1 TURNZIN TURN 4lrN TURNA RESIZE S Table 1 Simple turtle programs for generating polygons stars and spirals by iterating the basic turtle commands For the spiral program A is a fixed angle and S is a fixed scalar 04 Figure 6 A pentagon a five pointed star and a spiral generated by the programs in Table 1 Here the spiral angle A 47x 5 and the scale factor for the spiral is S 910 With a bit more ingenuity and with some help from the Law of Cosines we can program the turtle to generate more complicated shapes such as the wheel and the rosette see Figure 7 Figure 7 The Wheel and the rosette The Wheel is simply a regular polygon together with the lines connecting its vertices to its center The rosette is a regular polygon together with all its diagonals that is With the lines joining every vertex to every other vertex The Wheel displayed here has 15 sides and the rosette has 20 sides We leave it as a challenge to the reader to develop simple turtle programs that generate these shapes using the Law of Cosines to precalculate the lengths of the radii and the diagonals see Exercise 7 The turtle commands FORWARD TURN and RESIZE are used to translate rotate and scale the turtle In LOGO we can also develop turtle programs SHIFT SPIN and SCALE to translate rotate and scale other turtle programs see Table 2 Examples of SHIFT SPIN and SCALE applied to other turtle programs as well as to each other are illustrated in Figures 8 10 SHIFT Turtle Program SPIN Turtle Program SCALE Turtle Program REPEAT N TIMES REPEAT N TIIVIES REPEAT N TIIVIES Turtle Program Turtle Program Turtle Program MOVE D TURN A RESIZE S Table 2 Turtle programs that translate rotate and scale other turtle programs DD Figure 8 The effect of applying the SHIFT program to the turtle program for generating a square Figure 9 The effect of SCALE and SPIN On the left the SCALE program is applied to the turtle program for generating a star39 on the right the SPIN program is applied to the turtle program for generating a rosette I Figure 10 The effect of composing SPIN with SCALE starting with a triangle left a star center and a pentagon right Shapes built by iteration are cute to visualize and fun to build but by far the most interesting and exciting shapes that can be created using Turtle Graphics are generated by recursion In our next lecture we shall show how to design fractal curves using recursive turtle programs 4 Summary Turtle programming is the main theme of this lecture but this chapter also includes several important leitmotifs In addition to gaining some facility with turtle programming you should also pick up on the following distinctions that will be featured throughout this course First there is an important difference between points and vectors Although in the plane both points and vectors are typically represented by pairs of rectangular coordinates conceptually points and vectors are different types of objects with different kinds of behaviors Points are affected by translation vectors are not Vectors can be rotated and scaled points cannot Thus if the turtle is in state P w then the FORWARD command translates the point P but leaves the vector w unchanged Similarly the TURN and RESIZE commands rotate and scale the vector w but leave the point P unchanged Second there are two ways of approaching geometry conceptual and computational On the conceptual level when we think about Euclidean geometry we think about lengths and angles Thus when we program the turtle we use the FORWARD TURN and RESIZE commands to affect distances and directions Only when we need to communicate with a computer W only when we need to perform actual computations W do we need to descend to the level of coordinates Coordinates are a low level computational tool not a high level conceptual device Coordinates are akin to an assembly language for geometry Assembly languages are effective tools for communicating efficiently with a computer but generally we do not want to think or write programs in an assembly language rather we want to work in a high level language We shall try to keep 7 these two modes concepts and computations distinct throughout this course by developing novel ways to think about and to represent geometry The turtle is only the first of many high level devices we shall employ for this purpose Exercises 1 In classical LOGO the programmer can control the state of the pen by two commands PENUP and PENDOWN When the pen is up the FORWARD command changes the position of the turtle but no line is drawn The default state is pen down Explain why the MOVE D command is equivalent to the following sequence of turtle commands PENUP FORWARD D PENDOWN 2 In classical LOGO the turtle s state is represented by a pair P A where P is the turtle s position and A is the angle between the turtle s heading and a fixed direction in the plane The position P is stored by the xy coordinates of the point P relative to a global coordinate system and the angle A is the angle between the turtle s heading and the x axis of this global coordinate system a Show how to implement the FORWARD and TURN commands using this representation for the turtle s state Suppose we add to the turtle s state a scalar S representing the turtle s step size b Show how to implement the FORWARD TURN and RESIZE commands using the representation P A S position angle step size for the turtle s state c What are the advantages and disadvantages of the representation P A S for the turtle s state compared to the representation P w given in the text 3 Write a turtle program that draws a circle circumscribed around a a polygon with an arbitrary number of sides b a star with an arbitrary number of vertices 4 Consider the program STAR in Table 1 a For what integer values of N gt 5 does the program STAR fail to draw a star b What happens if the command TURN 4n N is replaced by TURN 8n N 5 Consider the program NEWSTAR N REPEAT N TIMES FORWARD 1 TURN 7r 7r N a How do the stars drawn by this NEWSTAR program differ from the stars drawn by the STAR program in Table 1 b How do the stars drawn by this NEWSTAR program differ for even and odd values of N Explain the reason for this curious behavior 6 Consider the program TRISTAR N REPEAT N TIMES FORWARD 1 TURN 2n 3 FORWARD 1 TURN 2nN 27r 3 a How do the stars drawn by this TRISTAR program differ from the stars drawn by the STAR program in Table 1 b Suppose that the command TURN 2n 3 is replaced by the command TURN x for an arbitrary angle a and that the command TURN 2n N 2n 3 is replaced by the command TURN 3 Show that the TRISTAR program still generates a star provided that 05 3 2n N and Na gt 231 What happens when Na 2n 7 Write a turtle program that for a regular polygon with an arbitrary number of sides draws a a wheel b a rosette Hint See Figure 11 Figure 11 The Law of Cosines provides a relationship between the length of a side and the distance from a vertex to the center of a regular polygon left Similarly the Law of Cosines provides a relationship between the distance from a vertex to the center of a regular polygon and the length of each diagonal of the polygon Notice that if the polygon has n sides then 3 2n n 8 Apply the SPIN program to the turtle program for a circle to generate the pattern in Figure 1 left 9 Write a turtle program that draws an ellipse 10 Prove that the turtle commands TURN and RESIZE commute by showing that if the turtle starts in the state P w then after executing consecutively the commands TURN A RESIZE S the turtle will arrive at the same state as when executing consecutively the commands RESIZE S TURN A Explain intuitively why this phenomenon occurs 11 Let wJ denote the vector perpendicular to the vector w of the same length as w Show that if w uv then wJ v u Hint Use the distance formula and the Pythagorean theorem to show that AAOB in Figure 12 is a right triangle A vu B uv Figure 12 The vectors w u v and wJ v u form a right angle at the origin 0 Lecture 22 Hidden Surface Algorithms thou didst hide thy face and I was troubled Psalm 307 1 Hidden Surface Algorithms Surfaces can be hidden from view by other surfaces The purpose of hidden surface algorithm is to determine which surfaces are obstructed by other surfaces in order to display only those surfaces visible to the eye In theory hidden surface algorithms are required for all types of surfaces in practice we shall restrict our attention to polygonal models In this lecture we shall assume that all the surfaces are planar polygons and that all the polygons are opaque We shall not assume that the polygons necessarily enclose a solid nor that the polygons form a manifold Our objective is given any collection of polygons to display only those polygons visible to the eye Polygonal models of complicated shapes may contain millions of polygons so just like shading algorithms the emphasis in hidden surface algorithms is on speed A good hidden surface algorithm must be fast as well as accurate Sorting tailored data structures and pixel coherence are all employed to speed up hidden surface algorithms There are two standard types of hidden surface algorithms image space algorithms and object space algorithms Image space algorithms work in pixel space the frame buffer and are applied after pseudoperspective object space algorithms work in model space and are applied before pseudoperspective These algorithms have the following generic structures Image Space Algorithm Object Space Algorithm For each pixel For each polygon Find the closest polygon Find the unobstructed part of the polygon Render the pixel with the color Render this part of the polygon and intensity of this polygon The speed of image space algorithms is 0nN where N is the number of pixels and n is number of polygons because for each pixel we must examine every polygon The speed of object space algorithms is 0n2 where n is the number of polygons because to determine which part of each polygon is visible we need to compare every polygon with every other polygon Many hidden surface algorithms have been developed each with their own advantages and disadvantages We shall examine ve of the most common hidden surface algorithms z buffer scan line ray casting depth sort and bsp tree The z buffer and scan line algorithms are image space algorithms the depth sort and bsp tree algorithms are object space algorithms Ray casting can work both in image space and in object space We will compare and contrast the relative merits and limitations of each of these algorithms and we shall see that there is no single solution to the hidden surface problem that is optimal in all situations 2 The Heedless Painter The heedless painter displays the polygons in a scene in the order in which they occur in some list Polygons that appear early in the list can be overpainted by polygons that appear later in the list The heedless painter is slow because the same pixel may be painted many times once for each polygon that lies over the pixel Worse the scene displayed by the heedless painter is often incorrect because polygons that appear later in the list may overpaint polygons that appear earlier in the list even though the later polygons actually lie behind the earlier polygons The heedless painter procedure is not a true hidden surface algorithm Nevertheless valid hidden surface algorithms can be generated by fixing the problems in the heedless painter procedure We begin with two such hidden surface algorithms z buffer and scan line 3 ZBuffer Depth Buffer The z buffer or depth buffer algorithm employs a special data structure called the zbu er or depth bu er The z buffer is a large memory array which is the same size as the frame buffer that is the z buffer stores an entry for each pixel This entry consists of the current depth as well as the current color or intensity of the corresponding pixel Using this data structure the z buffer algorithm proceeds much as the heedless painter visiting each polygon in turn but with one crucial difference a pixel is overpainted that is a new color or intensity is stored in the z buffer only if depth of current polygon at pixel lt current depth of pixel in zbu er The z buffer begins with the color or intensity of each pixel initialized to the background color or intensity and the depth of each pixel initialized to infinity To make the z buffer algorithm as fast as possible the depth of the pixels in each polygon can be computed incrementally To compute the depth of each pixel incrementally we proceed almost exactly as we did in 2 Lecture 21 for Gouraud and Phong shading where we computed the intensities and normal vectors at the pixels of a polygon incrementally i First compute the depth at the vertices of the polygon After pseudoperspective this depth is typically just the value of the z coordinate at each vertex ii Next compute the depth along the edges of the polygon 11 Finally compute the depth along scan lines for the pixels in the interior of the polygon The explicit details of this computation are given below Recall that for a line Mt passing through the points P1P2 Mt1 tP1tP2 P1 tP2 P1 Mt At P1t AtP2 P1 Subtracting the first equation from the second equation yields AL AtP2 P1 or equivalently AxAtx2 x1 AyAty2 y1 AzAtZZ Zl Thus along any line we can compute depth incrementally by setting Znexl Zcurrenl AZ Along a scan line Z2 Z1 1 Ax1gtAt gtAz 36 X1 362 361 and when we move to the next scan line along a polygonal edge Ay1gtAt gtAz Y2 Y1 Y2 Y1 If these computations are not completely familiar you should review Gouraud shading in Lecture 21 Section 3 The advantages of the z buffer algorithm are that the z buffer is simple to understand and easy to implement the disadvantages are that the z buffer is memory intensive and relatively slow since this algorithm may repaint the same pixel many times The next algorithm we shall study avoids both of these drawbacks by introducing more complicated data structures 4 Scan Line The scan line algorithm paints the pixels scan line by scan line To decide which polygon to paint for each pixel the scan line algorithm for hidden surfaces maintains two special data structures an active edge list and an edge table Ymax currentXint current Zint Ax A pointer to polygon where me maxy1 y2 2 maximum value ofy along the edge currentXint x coordinate of the point where the edge intersects the current scan line currentZint z coordinate depth of the point where the edge intersects the current scan line 262 x1 Ax 2 change in 6 along the edge when mov1ng to the next scan line Y2 Y1 z z Az 2 change 1n 1 along the edge when mov1ng to the next scan line Y2 Y1 pointer to polygon points to the polygon containing the edge The expressions for Ax and Az can be derived in the same way as the formula for Az in the Z buffer algorithm For each scan line we also introduce an edge table consisting of a list of those edges whose lower vertex lies on the scan line The data stored for each edge in the edge table is the same as the data that is stored for each edge in the active edge list New edges must be introduced into the active edge list as they become active and old edges must be removed as they become inactive Updating the active edge list is performed by the following algorithm Updating the Active Edge List For each edge in the active edge list If stn line gt Ymax delete the edge from the active edge list Otherwise update the values of current Xth and currentZint current Xth currentXint Ax currentZim current 2th Az Insert each edge in the edge table for the current scan line stn line into the active edge list Sort the active edge list by increasing values of currentXim We can now use the following scan line algorithm to paint the scene and avoid hidden surfaces Scan Line Algorithm For each scan line Update the active edge list see above algorithm For each polygon P with an edge in the active edge list compute Azp along the current scan line see discussion below Initialize Current Polygon polygon corresponding to the first edge in the active edge list Current Pixel currentXint for the first polygon in the active edge list Repeat until the scan line reaches the pixel on the last edge in the active edge list For each polygon P corresponding to an edge in the active edge list with current Xth gt Current Pixel Compute the z value Z of the polygon P at the Current Pixel see discussion below Determine the pixel x P if any where the polygon P crosses in front of the Current Polygon see discussion below If no polygon crosses in front of the Current Polygon Fill the pixels along the scan line from the Current Pixel to the end of the Current Polygon with the color and intensity of the Current Polygon Set Current Polygon the next polygon in the active edge list with currentXint greater than or equal to the last filled pixel Current Pixel currentXint for Current Polygon Otherwise Set x S the smallest value of x P Q polygon corresponding to xs Fill the pixels along the scan line from the Current Pixel to xs with the color and intensity of the Current Polygon Set Current Polygon Q Current Pixel x 3 To be active a polygon P must have at least two edges in the active edge list The value Azp for the polygon P along the current scan line is given by z z MP x2 351 where Z j currentZim and x j currentxmt 5 for the two edges of the polygon P in the active edge list The z value Z of a polygon P at the Current Pixel is given by Z p currentht currentth CurrentPixelAzP where currentZim and current Xth are the values in the edge table for any one of the edges in the active edge list belonging to the polygon P For an alternate approach see Exercise 1 The only real difficulty in the scan line algorithm is to determine where to switch polygons see Figure 1 Mathematically our problem is given the depths zpzQ of two polygons PQ at the same point along a scan line find the pixel at which the polygons intersect We can compute depth incrementally along a scan line just as we did in the z buffer algorithm by adding Az Let N be the number of pixels from the Current Pixel to the pixel where the crossover occurs At the pixel where the crossover occurs the depths of the two polygons are equal Therefore zPNAzP zQNAzQ ZQ Zp AZPAZQ The number N tells us how many more pixels we must visit before we switch to the next polygon Note that at most one crossover can occur between any pair of polygons so once we switch polygons we never switch back Of course if Current Pixel N is greater than the x coordinate of last pixel in the Current Polygon then no crossover occurs m scan line Figure 1 Crossover The main advantage of the scan line algorithm is speed The scan line algorithm is faster than the z buffer algorithm for two reasons the scan line algorithm avoids overpainting pixels each pixel is visited and painted only once and the scan line algorithm takes advantage of pixel coherence adjacent pixels typically lie on the same polygon and accordingly can be painted with the same color and intensity Another important advantage of the scan line algorithm is that the scan line algorithm is compatible with the algorithms for Gouraud and Phong shading If we use the scan line algorithm then hidden surfaces and shading can both be computed in the same pass since both algorithms proceed scan line by scan line The main disadvantage of the scan line 6 algorithm is that this algorithm requires more complicated data structures than the z buffer algorithm and the algorithm itself is a good deal more difficult to implement 5 Ray Casting The ray casting algorithm for hidden surfaces employs no special data structures Instead as in recursive ray tracing a ray is fired from the eye through each pixel on the screen in order to locate the polygon in the scene closest to the eye The color and intensity of this polygon is displayed at the pixel Ray Casting Algorithm Through each pixel fire a ray from the eye Intersect the ray with the plane of each polygon Reject intersections that lie outside the polygon Accept the closest remaining intersection that is the intersection with the smallest value of the parameter along the line Ray casting is easy to implement for polygonal models because the only calculation required is the intersection of a line with a plane Let L be the line determined by the eye point E and a pixel F and let S be a plane determined by a unit normal N and a point Q Then the parametric equation of the line is LU E tv where v F E and the implicit equation of the plane is N 39 P Q 0 Thus the line intersects the plane when N39Lt Q N39E tv Q 0 Solving for tyields tN39Q E 31 NW The actual intersection point can be found by substituting this value of t into the parametric equation of the line For polygonal models we still need to determine if this intersection point actually lies inside the polygon For convex polygons such tests are provided in Lecture 19 Section 3 for arbitrary polygons inside outside tests are discussed in Lecture 11 Section 7 Ray casting can be applied either before or after pseudoperspective The only difference is that after pseudoperspective the eye is mapped to infinity so the rays are fired perpendicular to the plane of the pixels rather than through the eye Thus in Equation 31 v is the normal to the pixel plane the remainder of the algorithm is unchanged Employed after pseudoperspective ray casting is an image space algorithm invoked before pseudoperspective ray casting is an object space algorithm The main advantage of the ray casting algorithm for hidden surfaces is that ray casting can be 7 used even with non planar surfaces All that is needed to implement the ray casting algorithm for hidden surfaces is a linesurface intersection algorithm for each distinct surface type in the model The main disadvantage of ray casting is that the method is slow Ray casting is a brute force technique that makes no use of pixel coherence For adjacent pixels it is quite likely that the same polygon is closest to the eye but ray casting makes no attempt to test for this pixel coherence Instead ray casting employs dense sampling so the ray casting algorithm for hidden surfaces is typically slower than other methods that employ more sophisticated data structures 6 Depth Sort Depth sort is another variation on the heedless painter s algorithm The data structure for depth sort is a list of polygons sorted by increasing depth Two polygons that overlap in depth are said to con ict Con icts are resolved by a sorting algorithm which is done in object space so depth sort is an object space algorithm After all the con icts are resolved the polygons are painted in order from back to front Degth Sort Algorithm Sort the polygons by the furthest vertex from the screen For each polygon find the minimum and maximum values of z depth at the vertices Sort the polygons in order of decreasing maximum z coordinates Resolve z overlaps see below Paint the polygons in order from farthest to nearest The main difficulty in implementing depth sort is resolving z overlaps Notice that without this step the depth sort algorithm would overpaint near polygons by far polygons just like the heedless painter s algorithm Below is a five step procedure for resolving conflicts z overlaps Here the terms zextents refers to the minimum and maximum values of the z coordinates xextents and yaxtentr are defined in an analogous manner Resolving Con icts For every pair of polygons P and Q If the z extents of P and Q overlap then perform the following five tests i Do the x extents fail to overlap ii Do the y extents fail to overlap iii Does every vertex of P lie on the far side of Q 8 iv Does every vertex of Q lie on near side of P v Do the xy projections of P and Q fail to overlap If any test succeeds P does not obscure Q so draw P before Q Otherwise we cannot resolve the con ict so split the polygon P by the plane of the polygon Q see below The ve tests are ordered by difficulty from easy to hard The x extents and y extents of a polygon are easy to detennine by examining the x and y coordinates of all the vertices of the polygon If the x extents or y extents of P and Q fail to overlap then it does not matter which polygon is painted rst since the projections of P and Q on the screen will not overlap see Figure 2 z axis x axis Figure 2 The z extents of P and Q overlap but the x extents do not overlap Therefore the projections of P and Q into the xy plane will not overlap If every vertex of P lies on the far side of the screen from Q or if every vertex of Q lies on the near side of the screen from P then P does not obscure Q so we can safely paint P before Q see Figures 34 We can determine if P lies on the far side of Q by computing one dot product for every vertex of P Fix a vertex VQ of Q and let NQ be the outward pointing normal the normal pointing to the far side of the screen the side of the screen away from the eye of the plane containing the polygon Q Then P lies on the far side of Q if and only if for every vertex VP of P VP VQ 39N Q gt 0 see Figure 3 Similarly fix a vertex VP of P and let N P be the outward pointing normal of the plane containing the polygon P Then Q lies on the near side of P if and only if for every vertex VQ of Q V P VQ 39NP gt 0 see Figure 4 Notice in Figure 4 that Q lies on the near side of P even though P does not lie on the far side of Q so the third and fourth tests are independent If tests iii and iv fail we can reverse the roles of P and Q and retest Figure 3 Plies onthe far side on VP VQ 39NQ gt0 Eye 0 Screen l NP Figure 4 Q lies on the near side of P V P VQ 39NP gt 0 Notice that P does not lie on the far side of Q If the first four tests fail then we can apply inside outside tests to determine if the projections of P and Q on the screen overlap If any vertex in the projection of P lies inside the projection of Q or if any vertex of Q lies inside the projection of P then the projections of P and Q on the screen overlap For convex polygons inside outside tests are provided in Lecture 19 Section 3 for arbitrary polygons inside outside tests are discussed in Lecture 11 Section 7 If the projections of P and Q do not overlap then once again it does not matter which polygon is painted first However if the projections of P and Q do overlap then the con ict cannot be resolved and we must split one of the polygons say P by intersecting the polygon P with the plane of the polygon Q Since splitting will be used again for bsp trees we present the details of this splitting procedure below in a separate subsection This method of resolving con icts works for con icts between pairs of polygons but not all con icts can be resolved in this manner because not all con icts are localized to pairs of polygons 10 ms 9 Qahscms x amRahscules p even thmlgh than s m can m between anypan afpalygans m mg 5 my special mam canamy he avamnymamngamspmmgm hmmemmz pa am That can he Eyck mm W p m m mam advantages uf m dzpth sun 3152mm rm 1mm 5mm 13 um m m 5mm 1 mp1 77 pm an mdzxzd us at palygans quotand m zmnng alganmm s mgm mwald 77 pm yam m palygars m nu mu m whlch may appeanmh 1m 11 mammsadvamag at mm m 13 um camms may he nunmum mm mm wum case If a m mm mu m we med m mn m a sphmng algaan m 3mm mmamex pulyga s lmmgcan he shunIcky mevex mmgamnsa vmgcychc camm may 315a he mmcu m an E guns Acychccan lm Pahscms g Qahscmsx RahscmsP 51 mm Spmng Ta spins palygan man5 an bath was at a md pm we must m m mam W m gvenplam mmmcts m plan at m palygan W m mmmcuhls 1m wnhthz edges a hz palygama spunk palyganmm pulygana segmzmsthauu an elthzrsldz at m sphmngplar eume mm m mamaam pm u Nm 7 Mp Tm pm mmmcunahr Ldzmrmmzdhyapam Qamamxzc nnwcme mm H smma wecanchnase N an Q N39QWz39NzWrWI39NzWZ NZ39QM39N1N1W139N1M W X n In fact it is easy to see that the vector N is perpendicular to both planes since N N1 XN2J N1N2 Hence N is parallel to the line L Similarly it is straightforward to verify that the point Q satisfies the equations of both planes see Exercise 2 and hence the point Q lies on the line L Once we have a point Q and a direction vector N for the line L we can split the polygon by intersecting L with every edge of the polygon Two coplanar lines L1s P su 12 t Q W intersect when L1s L20 that is when P su Q tv or equivalently when su IV Q P Dotting both sides rst with u and then with v yields two linear equations in two unknowns su39u tv 39u Q P 39u su39v tv39v Q P 39v Solving for gt gives the parameters of the intersections points and substituting s into the expression for L1 or tinto the expression for LZ gives the coordinates of the intersection point For further details see Lecture 11 Section 7 Since edges are bounded line segments if the polygon is convex the line L actually intersects only two edges of the polygon If L1s represents the line corresponding to an edge 1 of the polygon and u EH Pi then L20 intersects the edge EPlH if and only if at the intersection point of the two lines 0 s s s 1 Thus it is easy to detect which edges of the polygon are intersected by L and to split the polygon accordingly see Figure 6 P1 Figure 6 A polygon P0 P1P2P3P4 split by a straight line into two polygons P0P1QR and QP2P3P4R 7 BSPTree A binary space partitioning tree Imp tree is a binary tree whose nodes contain polygons For each node in a bsp tree all the polygons in the left subtree lie behind the polygon at the node while all the polygons in the right subtree lie in front of the polygon at the node Each polygon has a xed normal vector and front and back are measured relative to this fixed normal Once a bsp tree is constructed for a scene the polygons are rendered by an in order traversal of the bsp tree Recursive algorithms for generating a bsp tree and then using the bsp tree to render a scene are presented below Algorithm for Generatin a ESP Tree Select any polygon plane in the scene for the root Partition all the other polygons in the scene to the back left subtree or the front right subtree Split any polygons lying on both sides of the root see Section 61 Build the left and right subtrees recursively ESPTree Rendering Algorithm In Order Tree Traversal If the eye is in front of the root then Display the left subtree behind Display the root Display the right subtree front If eye is in back of the root then Display the right subtree front Display the root Display the left subtree back To generate a bsp tree we must be able to determine on which side of a plane a polygon lies and to split polygons that lie of both sides of a plane Consider a plane defined by a point Q and a normal vector N For any point P there are three possibilities i P lies in front of the plane ltgt N 39 P Q gt 0 ii P lies on the plane ltgt N 39P Q 0 iii P lies behind the plane ltgt N 39 P Q lt 0 If all the vertices of a polygon lie in front of a plane then the entire polygon lies in front of the plane if all the vertices of a polygon lie behind a plane then the entire polygon lies behind the plane Otherwise part of the polygon lies in front and another part lies behind the plane In this case we split the polygon by the plane using the procedure presented in Section 61 The main advantage of the bsp tree algorithm for hidden surfaces is that we can use the same bsp tree for different positions of the eye Thus when we want to move around in a scene the bsp tree is the preferred approach to hidden surfaces The main disadvantage of bsp trees is the work involved in splitting polygons 8 Summary We have discussed five different hidden surface algorithms z buffer scan line ray casting depth sort and bsp tree Table 1 contains a summary of the main features of each of these algorithms Two key ideas are applied to help increase the speed of these algorithms sorting of edges by depth and pixel coherence for depth and intensity We can speed up some of these algorithms still further by storing bounding boxes for each polygonal face and avoiding interference tests when the bounding boxes do not overlap Algorithms for finding hidden surfaces and procedures for producing shadows use essentially the same computations hidden surface algorithms find surfaces invisible to the eye shadow procedures find surfaces invisible to a light source Thus we can use the same algorithms for computing hidden surfaces and for calculating shadows Moreover we can often save time by reusing calculations We can move the eye point and reuse shadow calculations similarly we can move light source and reuse hidden surface computations Algorithm 1M Mg Coherence Z Bu er Image Space None Depth Calculations Scan Line Image Space Edges in the Intensity Calculations Active Edge List Ray Casting ImageObject Space None None Depth Sort Object Space Polygons Intensity Calculations BSPTree Object Space Polygons in Tree Intensity Calculations Table 1 Properties of hidden surface algorithms Exercises For each polygon P let AP 6 B P y C P z DP 0 be the equation of the plane of the polygon P Using these equations find a the value Z of the depth of the polygon P at x Current Pixel y stn line b Azp the change in depth of the polygon P as 6 moves from pixel to pixel along y Yscan line c the x coordinate where the polygon Q intersects the polygon P along y stn line Consider two planes N1 39 P Q1 0 N2 39P Q2 0 a Show that if N139Q1N2 39N2N1 N139N2N2N239Q2N139N1N2 N1 39N2N1 Q N1XN22 then N1 39QQ1 0 N2 39Q Q2 0 b Conclude that the point Q lies on the line representing the intersection of these two planes Programming Projects 2 Implement the ve hidden surface algorithms discussed in this lecture in your favorite programming language using your favorite API a Use your implementations to render several large polygonal models b Compare the relative speeds of the five algorithms for each of your models Integrate the scan line hidden surface algorithm with Gouraud or Phong shading to simultaneously remove hidden surfaces and eliminate Mach bands 3 Implement the bsp tree hidden surface algorithm and use this procedure to display the same models from several different points of view Lecture 16 Color and Intensity and he made him a coat of many colours Genesis 373 1 Introduction To display a picture using Computer Graphics we need to compute the color and intensity of the light at each point in the picture The purpose of this lecture is to explain how to represent color and intensity numerically and then to develop illumination models that allow us to compute the color and intensity at each point once we know the color location and intensity of the light sources and the physical characteristics of the objects in the scene 2 The RGB Color Model Color forms a 3 dimensional vector space The three primary colors red green and blue are a basis for this vector space every color can be represented as a linear combination of red green and blue The unit cube is often used to represent color space see Figure 1 Black is located at one comer of the cube usually associated with the origin of the coordinate system and the three primary colors are placed along the three orthogonal axes Intensity varies along the edges of the cube with the full intensity of each primary color corresponding to a unit distance along the associated edge Every combination of color and intensity is then represented by some linear combination of red green and blue where the coef cients of each primary color lie between zero and one Thus for each color 0 there is a unique set of coordinates r g 1 inside the unit cube that represents the color 0 The numerical values r g 17 represent intensities the higher the value of r or g or b the greater the contribution of red or green or blue to the color 0 This model is known as the RGB color model and is one of the most common color models in Computer Graphics Cyan white ma ema blue I g I I 766 yellow black red Figure 1 The RGB color cube Every color and intensity is represented by a linear combination of the red green and blue where the coefficients of each primary color lie between zero and one Pairs of primary colors combine to form colors complementary to the missing primary Thus redgreenyell0w which is the color complementary to blue Similarly bluegreencyan which is the color complementary to red and blueredmagenta which is the color complementary to green Combining all three primaries at full intensity yields whiteredgreenblue which lies at the corner of the cube diagonally opposite to black Shades of gray are represented along the diagonal of the cube joining black to white In the remainder of this lecture we shall develop illumination models These illumination models allow us to render a scene by computing the r g 17 color intensities for each surface point once we know the light sources and the physical characteristics of the objects in the scene We shall consider three illumination models ambient light diffuse reflections and specular highlights 3 Ambient Light Ambient light is light that is re ected into a scene off outside surfaces For example sunlight that enters a room through a window by bouncing off nearby buildings is ambient light Ambient light softens harsh shadows generated by point light sources Thus ambient light helps to make scenes rendered by Computer Graphics appear more natural Typically we assume that the intensity In of the ambient light in a scene is a constant What we need to compute is the intensity I of the ambient light re ected to a viewer from each surface point in the scene The formula for this intensityI is simply I ka1a 31 where 0 5 ka 51 is the ambient re ection cae icient The ambient reflection coefficient ka is a property of the color and material of the surface which can be determined experimentally or simply set by the programmer Notice that the intensity I is independent of the position of the viewer Equation 31 is really three equations one for each primary color red green and blue If we set In 11 IZ and ka krk k where 121512 are the ambient intensities for red green and blue and krk kg are the ambient reflection coefficients for red green and blue then Equation 31 becomes I ngb k l k l akili 32 Notice that if the ambient light is white then In 111 so the color of the light reflected from a surface is the color of the surface However if the color of the ambient light is blue and the color of the surface is red then In 001 and ka kr00 so 1 rgb 000 and the color perceived by the viewer is black 4 Diffuse Re ection Diffuse lightis light re ected off dull surfaces like cloth Light dispersed from dull surfaces is re ected from each point by the same amount in all directions Thus the intensity of the re ected light is independent of the position of the viewer Here we shall compute the diffuse light re ected off a dull surface from a point light source Let p be the intensity of the point light source We need to compute the intensity I of the diffuse light re ected to a viewer from each point on a dull surface Let L be the unit vector from the point on the surface to the point light source and letN be the outward pointing unit normal at the point on the surface see Figure 2 Then the formula for the diffuse intensity is simply IkdL39NI 41 where 0 s kd s 1 is the di use re ection coefficient The diffuse re ection coef cient kd like the ambient re ection coef cient ka is a property of the color and material of the surface which can be determined experimentally or simply set by the programmer L N S arface Figure 2 The unit normal vector N to a point on the surface and a unit vector L pointing in the direction of a point light source Equation 41 is a consequence of Lambert s Law Consider a point light source far away from a small surface facet see Figure 3 Let I facet denote the intensity of light on the facet and let I source denote the intensity of the light source Then Light Beam Cross Section x I Unit Area Facet Area facet SUM3968 39 But we can see from Figure 3 that Beam Cross Section cos0 Facet Area where 0 is the angle between the normal to the facet and the vector to the light source Thus we arrive at the following result Lambert s Law facet 0056 Isource 42 N 0 Cross Section 0 D Figure 3 Lambert s Law facet cos0 130W Beam Light Source In Equation 41 L and N are unit vectors Hence L39 N cos0 where 0 is the angle between the normal to the surface N and the direction to the light source L Thus Equation 4 1 is simply Equation 42 attenuated by the factor kd Equation 41 is really three equations one for each primary color red green and blue If we set Ip Iglijg and kd k k k5 where II IZ are the intensities of the point light source for red green and blue and k k k3 are the diffuse re ection coefficients for red green and blue then Equation 4 1 becomes I r gb L Nk51k 1 k312 43 When there are many light sources we simply add the contributions from each light source As with ambient light the color perceived by the viewer depends both on the color of the light source and the color of the surface If the light source is white then I p 111 so the color of the reflected light is the color of the surface However if the color of the light source is blue and the color of the surface is red then Ip 001 and kd 1920 0 so I rgb 0 0 0 and once again the color perceived by the viewer is black 5 Specular Re ection Specular reflections are highlights reflected off shiny surfaces Unlike ambient and diffuse reflections specular highlights are sensitive to the position of the viewer Here we shall compute the specular highlights reflected off a shiny surface from a point light source Let p be the intensity of the point light source We need to compute the intensity I of the 4 specular highlight re ected to a viewer from each point on a shiny surface Let L be the unit vector from the point on the surface to the point light source and letN be the outward pointing unit normal at the point on the surface Let R be the image of the vector L as the light from the point light source in the direction L bounces off the surface that is R is the vector defined by setting the angle of incidence of L equal to the angle of reflection of R Finally let Vbe a unit vector from the point on the surface to the viewer and let x be the angle between Vand R see Figure 4 Then the formula for the intensity I of the specular highlight seen by a viewer in the direction V is given by Ikscos x1p ksRV I 51 where 0 s ks s 1 is the specular re ection coefficient and n 2 0 is the specular exponent a constant that controls the concentration of the specular highlight The specular re ection coefficient ks like the ambient reflection coefficient ka and the diffuse reflection coefficient kd is a property of the color and material of the surface which can be determined experimentally or simply set by the programmer Surface Figure 4 The unit normal vector N to a point on the surface and a unit vector L pointing in the direction of a point light source The unit vector Vpoints to the viewer and the unit vector R is the image of the light vector L reflected off the surface The angle 0 is the angle between the vectors L and N and the angle a is the angle between the vectors R and V Notice that unlike ambient and diffuse reflections specular highlights depend on the position of the viewer The intensity of the specular highlight falls off rapidly as the angle a between the reflected vector R and the vector to the viewer V increases since R 39V cosx gt 0 as x gt 90 Moreover increasing the value of the specular exponent n further concentrates the specular highlight around the direction R since high powers of cosx approach zero more rapidly than low powers of cosx As n gt 00 the surface approaches a mirror only when x 0 is any effect visible to the viewer Conversely when n gt 0 neither the position of the viewer nor the position of the light source matters and the effect is much the same as for ambient light In Equation 51 the vectors LVJV are typically known since the position of the light source the location of the viewer and the shape of the surface are controlled by the programmer The 5 parameters I p and ks the intensity of the light source and the specular re ection coefficient are also controlled by the programmer The re ection vectorR however must be computed To find R let L and L i denote the components of L parallel and perpendicular toN see Figure 5 Then L um and RL LJ Now recall that I L39NN Li L LH L L39NN Therefore R2L39NN L Surface Figure 5 Computation of the vectorR from the vectors N and L L L Li and R L Li In the calculation of specular re ection we shall often assume that the light sources are located at infinity Notice that if the light source is far away and if the surface is planar then LNR are constants and only R 39V needs to be recalculated for each point on the surface Thus these assumptions help to speed up the calculation of specular re ections Equation 51 like Equations 31 and 41 is really three equations one for each primary 2 b b color red green and blue If we set IF Iglijp and ks krksgks where II Ip are the intensities of the point light source for red green and blue and ksrk gk5 are the specular re ection coefficients for red green and blue then Equation 51 becomes b I rgb R V k 1k 1 kd1 52 When there are many light sources we simply add the contributions from each light source Specular highlights come in two types depending on whether the surface material is 6 homogeneous or inhomogeneous When the surface material is homogeneous like a pure metal then the specular highlight takes on the color of the surface much like diffuse re ections Thus if the light source is white then I p 111 so the color of the specular highlight is the color of the surface However if the color of the light source is blue and the color of the surface is red then Ip 001 and kd kg00 so I rgb 000 and no specular highlight is visible to the viewer When the surface material is inhomogeneous like a plastic then unlike ambient light and diffuse re ections the color of the specular highlights perceived by the viewer depends only on the color of the light source and not on the color of the surface For example if the color of the light source is blue and the color of the surface is red then the color of the specular highlight is blue not red or black 6 Total Intensity To find the total intensity at each point we must add the ambient diffuse and specular components Thus Total Intensity Ambient Intensity Diffuse IntensitySpecular Intensity For each scene there is only one ambient intensity but for the diffuse and specular intensities we need to add the contributions from each light source Therefore Total Intensity 191 pkdL39NIpE kaR V 1 61 where the sums are taken over all point light sources As usual Equation 61 is really three equations one for each primary color Since in the RGB color model every color and intensity is represented by a point inside the unit cube when there are many light sources it may be necessary to normalize the total intensities to lie between zero and one by dividing the intensity at each point by the maximum intensity in the scene 7 Summary In the RGB color model each color and intensity is represented by three coordinates r g b in the unit cube each coordinate representing the contribution of the associated primary color red green or blue to the given color There are three illumination models for computing the color and intensity at each surface point ambient intensity diffuse re ection and specular highlights The formulas for these illumination models are summarized below Illumination Models Ambient Intensity kaIa Diffuse Re ection kdL 39 NIp Specular Re ection kSR 39 V 117 Total Intensity kaIa EpkdL 39 NIp EkaR 39 V 117 where L is the unit vector from the point on the surface to the point light source N is the outward pointing unit normal at the point on the surface R 2L39 N N L is the image of the vector L as the light from the point light source in the direction L bounces off the surface see Figure 5 V is a unit vector from the point on the surface to the viewer Ia is the ambient intensity I p is the intensity of the light source located at the point p ka is the ambient reflection coefficient kd is the diffuse reflection coefficient ks is the specular re ection coefficient n is the specular reflection exponent and the sums are taken over all the point light sources The distinguishing properties of these three illumination models are summarized in Table 1 Color Viewer Location Ambient Intensity Surface Independent Diffuse Reflection Surface Independent Specular Highlights Surface Dependent Homogeneous Specular Highlights Light Source Dependent Inhomogeneous Table 1 How the color and intensity at a point depends on the position of the viewer as well as the color of the surface and the color of the light source for ambient diffuse and specular reflections Exercises 1 Suppose that the color of the light source is yellow and the color of the surface is cyan What is the color perceived by the viewer for a b c diffuse reflection specular reflection homogenous material specular reflection inhomogeneous material 2 Show that the reflection vectorR in Figure 4 can be computed in each of the following ways a b C By finding the mirror image of the light vector L in the plane perpendicular to L i By rotating the light vector L by 180 around the axis vector N By finding the mirror image of the light vector L in the plane perpendicular to N and then negating the result Lecture 30 Subdivision Surfaces To give snbtilty t0 the simple Proverbs 14 1 Motivation Subdivision algorithms are similar to fractal procedures In the standard fractal algorithm we begin with a compact set C0 and iterate over a collection of contractive transformations W to generate a sequence of compact sets Cn1 WC that converge in the limit to a fractal shape Ccgt0 LimneooC In subdivision procedures we start with a set P0 usually either a control polygon or a control polyhedron or as we shall see shortly a quadrilateral or triangular mesh and recursively apply a set of rules S to generate a sequence of sets Pn1 SP of the same general type as P0 that converge in the limit to a smooth curve or surface PCgt0 LimnemPn Although one of the themes of Lecture 29 is that subdivision algorithms are essentially fractal procedures nevertheless the goals of subdivision algorithms and fractal procedures are fundamentally different The goal of fractal procedures is to construct extraordinary shapes unconventional forms from conventional origins the goal of subdivision algorithms is to construct smooth shapes differentiable functions from discrete data The de Casteljau subdivision algorithm for Bezier curves and surfaces and the Lane Riesenfeld algorithm for uniform B splines are examples of subdivision procedures that start with coarse control polygons or polyhedra and build refined control polygons and polyhedra that converge in the limit to smooth curves and surfaces We are interested in subdivision algorithms for four basic reasons i Subdivision algorithms replace complicated formulas with simple procedures Thus subdivision is more in the spirit of modern computer science than classical mathematics ii Subdivision algorithms are easy to understand and simple to implement Subdivision algorithms can generate a large class of smooth functions not just H H H polynomials and piecewise polynomials iV Subdivision algorithms on polyhedral meshes can produce shapes with arbitrary topology unlike tensor product schemes which can generate only surfaces that are topologically equivalent to a rectangle or by identifying edges to a cylinder or a torus Thus subdivision provides a simple approach to generating a wide variety of smooth shapes We are going to focus on subdivision algorithms for freeform surfaces Most of this chapter is based on Chapters 2 and 7 of Subdivision Methods for Geometric Design A Constructive Approach by Warren and Weimer We shall devote our attention here to the algorithmic details of different subdivision paradigms Readers interested in proofs of convergence differentiability and other properties of these subdivision procedures should consult the book by Warren and Weimer 2 Box Splines Box spline surfaces are generalizations of uniform tensor product B spline surfaces The fundamental step in the Lane Riesenfeld subdivision algorithm for uniform tensor product B spline surfaces is averaging adjacent control points along canonical directions in a rectangular array Box spline surfaces are generated by subdivision procedures that allow averaging along arbitrary directions in a rectangular array To understand how this works in practice we begin with a review of the Lane Riesenfeld algorithm for uniform B splines 21 Split and Average Recall that the Lane Riesenfeld algorithm Chapter 28 Section 41 for uniform B spline curves consists of two basic steps splitting and averaging see Figure 1 o o P0 P0P1 P1 131P2 P2 2 2 f f f K 7 K P0 P0 P1 Pl P2 P2 Figure 1 The Lane Riesenfeld algorithm for uniform B spline curves At the base of the diagram each control point is split into a pair of points Adjacent points are then averaged and this averaging step is repeated 11 times where n is the degree of the curve The new control points for the spline with one new knot inserted midway between each consecutive pair of the original knots emerge at the top of the diagram Iterating this procedure generates a sequence of control polygons that converge in the limit to the B spline curve for the original control points To extend the Lane Riesenfeld knot insertion procedure to uniform tensor product B spline surfaces Pst we need to insert knots in both the s and tparameter directions Consider a rectangular array of control points P17 To insert knots midway between each pair of consecutive knots we first split and average in the s direction and then split and average the result of this computation in the t direction see Figures 2 4 Alternatively instead of initially splitting each control point into two control points we can start by splitting each control point into four control points We can then average consecutively in the s and t directions now there is no need to split the output of the averages in the s direction before averaging in the t direction see Figure 5 The result of both approaches is the same control polyhedron and it makes no difference whether we average rst in the s direction and then in the t direction or first in the t direction and then in the 3 direction the result is always the same see Exercise 1a 0 o a 0 P02 PO2Pl2 Hz 1312P22 P22 P02 P02 1 12 P12 P22 P22 2 P01 POlPll Pll M P21 1001 P01 P11 P11 P21 P21 2 2 P00 M P10 M P20 Poo P00 P10 P10 P20 P20 2 2 a Split in the sdirection 17 Average in the sdirection Figure 2 Subdivision for uniform tensor product B spline surfaces First step a Split and 17 average in the s direction Here we illustrate the linear case Higher degree surfaces can be generated by taking additional averages P02 M Plz M P22 2 P02 P02P12 P12 P12P22 P22 H 2 P01 M 111M P21 2 2 P01 P01P11 P11 P11P21 PZI 2 2 P00 M Plo M P20 2 2 2 Split in the t direction Figure 3 Subdivision for uniform tensor product B spline surfaces continued The output of the first step Figure 2 right is split that is the points are doubled in the t direction P02 POZ 1312 P12 1312P22 P22 2 P1P02 H1P0213111312 1311P12 P11P12P21P22 1321P22 4 P01 P1Pll P P11P21 P21 2 11 2 PooPo1 POOPOlPlOPll 1310Pll 1310P11P20Pz1 P20P21 p00 Poo 1310 PlO 1310P20 P20 2 2 Average in the t direction Figure 4 Subdivision for uniform tensor product B spline surfaces Final step Average the points in Figure 3 in the t direction Here we illustrate the bilinear case Higher bidegree surfaces can be generated by taking additional averages a o 0 P02 P02 P12 P12 P22 P22 39quot P02 P2P12 P12 P12P22 P22 Iquot 2 2 POZ P02 Plz PIZ P22 P22 P02 M P12 P22 2 2 1001 P01 P11 P11 1321 P21 P01 P01P P P11P21 P21 2 2 P01 P01P11 Pr Po1 P01 P11 P11 1 21 P21 T P11P21 1321 2 P00 P00P10 P10 lO39l39PZO P20 P00 P00 P10 P10 P20 P20 2 P00 Poo P10 P10 M P20 39 39 39 P00 P00 P10 PIO P20 P20 2 2 a Split 1 Average Figure 5 Subdivision for uniform tensor product B spline surfaces alternative approach First a split each point into four points and then 17 average in the s direction The resulting points are the same as the points in Figure 3 We can now average the output in the t direction to get the points in Figure 4 No additional splitting is required 4 22 A Subdivision Procedure for Box Spline Surfaces Box spline surfaces are built by a generalization of the split and average approach to subdivision for uniform tensor product B spline surfaces The only difference is that for box splines in addition to averaging along canonical directions in the rectangular array of control points we also allow averaging along arbitrary directions in the rectangular array Thus to de ne a box spline surface in addition to a rectangular array of control points P17 in 3 space we need to specify a collection of vectors V v v1v2 in the plane The only restriction on the collection V is that the components v1v2 of each of the vectors v must be integers and V must contain at least one copy of the vectors 1 0 and 01 Note that vectors v in the collection V can appear multiple times The subdivision algorithm for a box spline surface begins by splitting each control point into four control points just as in the subdivision algorithm for uniform tensor product B spline surfaces see Figure 5 left We then remove one copy of the vectors 1 0 and 01 from the collection V Thus the initial copies of 10 and 01 correspond to quadrupling the control points Now we make one averaging pass for each remaining vector v v1v2 in the collection V by computing the averages of v adjacent points that is by computing all averages of the form Q IijPiv1jv2 2 The output of one averaging pass is used as input to the next averaging pass The order in which 21 we compute these averages does not matter since averaging v adjacent points and then averaging w adjacent points is equivalent to averaging w adjacent points and then averaging v adjacent points see Exercise 1b Iterating this procedure generates in the limit piecewise polynomial surfaces of degree d 2 where d is the number of vectors counting multiplicities in the collection V Moreover these surfaces have x 2 continuous derivatives where x is the size of the smallest set A C V such that the vectors in V A are all multiples of a single vector see Warren and Weimer Chapter 2 Example 2 Uniform Tensor Product BSpline Surfaces Let Vconsist of the vector 1 0 repeated m times and the vector 01 repeated 11 times The initial copies of 1 0 and 01 correspond to quadrupling the control points Thus repeating the vector 1 0 m times corresponds to taking m 1 averages in the s direction and repeating the vector 01 11 times corresponds to taking n 1 averages in the t direction Therefore the corresponding box spline surface is a uniform tensor product B spline surface of bidegree m 111 1 The total degree of this surface is d m 1 n 1 m n 2 and this surface has a 2 continuous derivatives where x minmn Example 22 Three Direction Linear Box Splines Let V 1 0 01 11 Then d 3 and x 2 Thus the corresponding surface is a continuous 3 direction piecewise linear box spline The vectors 1 0 and 01 correspond to quadrupling the control points Averaging these points in the direction 11 yields the points in Figure 6 P02 M P12 I12 P22 P22 2 2 P01P02 P01P12 P11P12 1311P22 P21P22 2 2 P P P P PO1 012 11 P11 112 21 p21 P00Po1 P00P11 P10P11 P10P21 P20P21 2 2 2 2 2 P00 Pooz plo P10 P10on P20 2 Figure 6 One level of subdivision for the 3 direction piecewise linear box spline in Example 22 These control points are generated by averaging the control points in Figure 5 left along the direction 11 that is by using Equation 21 with v1 v2 1 For an example see Figure 8 Example 23 Three Direction Quartic Box Splines Let V 1 010 01 011111 Then d 6 and x 4 Thus the corresponding surface is a 3 direction piecewise quartic box spline with two continuous derivatives The initial vectors 1 0 and 01 correspond to quadrupling the control points Averaging these points once in each of the directions 1 0 and 01 yields the points in Figure 4 Averaging twice more in the direction 11 generates the points in Figure 7 see Exercise 2 o 3P01P2Ii1312 P013P113112P22 8 8 3P11P1zPz13102 8 POO31gt0131gt111gt12 P00Rn110101111121511 2 P103P113P21P22 8 16 8 3P00Po1P103P11 P00 311103P11P21 3P10P11 D203P21 8 8 8 Figure 7 One level of subdivision for the 3 direction quartic box spline in Example 23 These control points are generated by averaging the control points in Figure 4 twice along the direction 11 For an example see Figure 9 6 Figure 8 A three direction piecewise linear box spline surface The initial control polygon is on the left the first two levels of subdivision are illustrated in the middle and on the right I 39 ll quot39 h 39 E It 391 I o I quotI i l I O 0 0quot i 39a 0 mnumu mmmm I 1 Iquot n n n 390 t 391 l n 0 390 n 4quot 5 E h 392 5 i E g h h O 0 D I In 1 O h Figure 9 A three direction quartic box spline surface The initial control polygonis in the upper left The first five levels of subdivision are illustrated from left to right and from top to bottom y 1 m n a mte I Il l39l39l39 quotlquotquot3939 i i z mumwn l t tg II39IIIlllllllliyllilllit I in lrmIItltlplquotunpitm quot01quot139I titi 439 Figure 10 The C1 biquadratic Bispline center and the C 2 three direction quartic box spline right for the same control polygon left Both surfaces employ four rounds of averaging for each level of subdivision 7 3 Quadrilateral Meshes A quadrilateral mesh is a collection of quadrilaterals where each pair of quadrilaterals are either disjoint or share a common edge and each edge belongs to at most two quadrilaterals One way to form a quadrilateral mesh is to start from a rectangular array of control points Joining points with adjacent indices generates a regular quadrilateral mesh a mesh where each interior vertex has four adjacent faces edges and vertices see Figures 8 9 10 Tensor product B splines are built from rectangular arrays of control points Therefore uniform tensor product B splines are an example of surfaces generated by subdivision starting from a quadrilateral mesh The goal of this section is to construct smooth surfaces starting from quadrilateral meshes of arbitrary topology Unlike tensor product or box spline schemes the vertices of an arbitrary quadrilateral mesh are not constrained to form a rectangular array all that is required is that the vertices can be joined into non overlapping quadrilateral faces where each pair of faces are either disjoint or share a common edge and each edge belongs to at most two faces For example the faces of a cube form a quadrilateral mesh even though the vertices of the cube do not form a regular rectangular array since in the cube each vertex has only three adjacent faces see Figure 14 Two additional examples of quadrilateral meshes that are not generated by rectangular arrays of points are illustrated in Figure 13a and Figure 15 Below we shall provide two methods for constructing smooth surfaces from arbitrary quadrilateral meshes via subdivision centroid averaging and stencils 31 Centroid Averaging Centroid averaging is an extension of the Lane Riesenfeld subdivision algorithm for uniform tensor product bicubic B spline surfaces from rectangular arrays of control points to quadrilateral meshes with arbitrary topology Therefore we begin by revisiting the Lane Riesenfeld algorithm for bicubic B splines 311 Uniform Bicubic BSpline Surfaces To simplify our discussion let us start with uniform B spline curves For cubic B splines the Lane Riesenfeld algorithm can be separated into two distinct stages topology connectivity and geometry shape In the topological stage corresponding to the first piecewise linear step of the Lane Riesenfeld algorithm we introduce new control points at the midpoints of the original control polygon and we change the connectivity of the control polygon by adding edges joining these new points to adjacent control points see Figure 1 and Figure 11b Notice however that in the topological phase we do not alter the shape of the control polygon In the geometric stage we reposition the control points by taking two successive averages Notice that computing two successive averages is equivalent to taking the midpoints of the midpoints of these control points see Figure 11c Thus in the geometric phase we change the shape of the control polygon but we do not alter the connectivity of the vertices and edges 8 a Original Control Points 17 New Topology c New Geometry Figure 11 One level of the Lane Riesenfeld algorithm for uniform cubic B spline curves In a a segment of the original control polygon black is illustrated In the topological stage 17 new control points yellow are introduced at the midpoints of the edges of the control polygon Notice that there are now two types of control points edge points yellow and vertex points black In the geometric stage c the control points black and yellow are repositioned to the midpoints blue of the midpoints green of these control points Edge points yellow are relocated along the same edge in fact to the same position along the edge but vertex points black are relocated to new positions off the original control polygon The new control polygon is illustrated in blue A similar interpretation applies to the Lane Riesenfeld subdivision algorithm for uniform tensor product bicubic B spline surfaces Once again the Lane Riesenfeld algorithm can be separated into two distinct stages topology connectivity and geometry shape In the topological stage we keep the original control points and we insert new control points at the midpoints of the edges and at the centroids of the faces of the control polyhedron see Figure 4 and Figure 12b Thus we alter the connectivity of the control polyhedron adding new edges and faces by connecting the centroid of each face to the midpoints of the edges surrounding the face Notice again that in the topological phase we do not alter the shape of the control polyhedron In the geometric stage we reposition these control points by taking two successive averages in the s direction and the t direction But successive averaging in the s and tdirections is equivalent to a single bilinear average of four adjacent control points since 1 Q1 Q11 1 Q11 Q111 Q1 Q1391 Q11 Q111 2 2 2 2 4 39 Therefore two successive averages in the s and t d39 quot are 1 39 to two 39 centroid averages of four adjacent control points Computing the centroid of adjacent centroids sends Q1 1 1 Q1 1 Q1 1 Q1 i Q1 1 Q11 1 Q1L Q1 4 4 4 1 Q1 gt 1 Q1 1 Q1 11 Q11 Q1 1 Q11 Q111 Q11 Q1 4 4 4 4 39 Therefore each control point is repositioned to the centroid of the centroids of the faces adjacent to 9 the control point see Figure 12c Thus in the geometric stage we change the shape of the control polyhedron but we do not alter the connectivity of the vertices edges and faces I a Original Control Points 17 New Topology c New Geometry Figure 12 One level of the Lane Riesenfeld algorithm for bicubic B spline surfaces In a we illustrate one face of the control polyhedron In the topological stage 17 new control points yellow are inserted at the midpoints of the edges and at the centroids of the faces of the control polyhedron each edge is then split into two edges and each face is split into four faces In the geometric stage 0 each control poin yellow or black is repositioned to the centroid blue of the centroids green of the faces adjacent to the control point Thus after the geometric stage each black and each yellow control point is repositioned based on the location of the green centroids of adjacent faces but the topology of the polyhedron is not changed The green centroids are used only to reposition vertices and are not themselves vertices of the refined polyhedron 312 Arbitrary Quadrilateral Meshes As with bicubic B splines there are two main phases to centroid averaging for arbitrary quadrilateral meshes topology connectivity and geometry shape In the topological phase we refine the mesh by introducing new vertices edges and faces but we do not alter the underlying shape of the mesh In the geometric phase we reposition the vertices to change the geometry of the mesh but we do not alter the underlying topology of the mesh rather we maintain the connectivity of the mesh the edges and faces introduced during the topological phase To refine the topology of the mesh we proceed exactly as we did for bicubic B splines we keep the original vertices and we insert new edge vertices at the midpoints of the edges and new face vertices at the centroids of the faces of the quadrilateral mesh Each edge is then split into two edges and each face is split into four faces by connecting the centroid of the face to the midpoints of the edges surrounding the face see Figure 13b To alter the geometry of the mesh we reposition each vertex of the mesh to the centroid of the centroids of the adjacent faces The only difference between subdivision for bicubic B splines and subdivision for arbitrary quadrilateral meshes is that for arbitrary quadrilateral meshes there need not be four faces adjacent to each interior vertex For example in the cube there are only three faces adjacent to each of the vertices An interior vertex of a quadrilateral mesh where the number of adjacent faces edges or vertices is not equal to four is called an extraordinary vertex and the number of faces edges or vertices adjacent to a vertex is called the valence of the vertex Thus in 10 the geometric phase each vertex Q of the mesh is repositioned by the formula 1 I Q gt E Ck 1 k1 where C1 C are the centroids of the faces adjacent to Q and n is the valence of Q After several levels of subdivision most of the interior vertices of a quadrilateral mesh are ordinary vertices and the extraordinary vertices become more and more isolated topologically from one another These features emerge because during the topological phase each face is subdivided into four faces by edges joining the centroid of the face to the midpoints of the surrounding edges Thus the new edge vertices and the new face vertices all have valence four see Figure 13b so all the new vertices introduced by subdivision are ordinary vertices Also the valence of each of the original vertices is unchanged since the number of faces surrounding a vertex does not change during subdivision Hence during subdivision ordinary vertices remain ordinary vertices and extraordinary vertices remain extraordinary vertices with the same valence see Figure 13b Since all the new vertices have valence four locally the new quadrilateral mesh looks exactly like a rectangular array of control points only vertices from the original mesh that did not have valence four do not have four adjacent faces Therefore just like uniform bicubic B splines the surfaces generated in the limit by iterating centroid averaging have two continuous derivatives everywhere the only exceptions are at the limits of the extraordinary vertices where these surfaces are guaranteed to have only one continuous derivative see Warren and Weimer Chapter 8 O 39 O a Extraordinary Vertex b New Topology c New Geometry Figure 13 One level of centroid averaging In a we illustrate six faces of a quadrilateral mesh surrounding an extraordinary vertex In the topological stage 17 new vertices are inserted at the midpoints yellow of the edges and at the centroids green of the faces and the centroid of each face is joined to the midpoints of the surrounding edges splitting each face into four new faces In the geometric stage 0 each vertex yellow green or black is repositioned to the centroid of the centroids blue of the faces adjacent to the vertex but the topology of the mesh is not changed Notice that the extraordinary vertex at the center remains an extraordinary vertex and is repositioned as the centroid of six adjacent centroids All the other vertices black yellow and green are ordinary vertices and their new location is computed as the centroid of four blue points just as in the Lane Riesenfeld algorithm for bicubic B splines 11 iac Ing quot quot W 3939quoti m quotn w r a yquot 8 r Figure 14 Four levels of centroid averaging applied to a cube The corners are rounded but the limit shape is not a perfect sphere Notice the extraordinary vertices of valence three at the corners of the cube Figure 15 Centroid averaging applied to two cubes connected by a thin rectangular rod The original quadrilateral mesh is on the left the first and third levels of subdivision are illustrated in the middle and on the right 32 Stencils Stencils are an alternative way to generate smooth surfaces via subdivision starting from quadrilateral meshes of arbitrary topology Centroid averaging separates the computation of new vertices during subdivision into two phases topology connectivity and geometry shape After the insertion of new vertices in the topological phase all the vertices old and new are repositioned by a single formula W centroid averaging This formula computes the new positions of the vertices in terms of the known positions of the vertices after the topological phase In contrast stencils compute the positions of all the new venices in terms of the positions of the original vertices Thus stencils combine the topological and geometric computations into a single phase 12 321 Stencils for Uniform BSplines Since centroid averaging is an extension of the Lane Riesenfeld subdivision algorithm for tensor product bicubic B spline surfaces from rectangular arrays of control points to quadrilateral meshes with arbitrary topology we shall adapt stencils for bicubic B spline surfaces to quadrilateral meshes of arbitrary topology As usual to simplify matters we will begin our study of stencils with stencils for cubic B spline curves The Lane Riesenfeld algorithm for cubic B spline curves is illustrated in Figure 16 see too Chapter 28 Section 41 41204411 P06P1P2 41314412 P16P2P3 4P24P3 8 8 8 8 8 3P0Pl P03P1 3P1P2 11713P2 3P2P3 P23P3 43044 A V2 f v2 f v Vi Figure 16 The Lane Riesenfeld algorithm for cubic B spline curves At the bottom of the diagram each control point is split into a pair of points Adjacent points are then averaged and this averaging step is repeated three times The new control points for the cubic spline with one new I knot inserted midway between each consecutive pair of the original knots emerge at the top of the diagram Notice that there are essentially two distinct explicit formulas for the new control points that emerge at the top of this diagram P P Qi1l2 1 1 31 2 Pi6Pi1 1Ei2 Qi1 8 32 The stencils for this algorithm are simply the coef cients 1 21 2 and 1 8 6 8 1 8 that appear in these two formulas To understand the geometry behind these two formulas recall from Figure 11 that after one 13 level of subdivision topologically the new control polygon for a cubic B spline curve consists of two types of control points edge points and vertex points Equation 31 repositions edge points Equation 32 repositions vertex points These stencils can be illustrated schematically by the diagrams in Figure 17 ltgt lop n 1 o e o g a edge stencil b vertex stencil NIH Figure 17 Stencils for subdivision of cubic B spline curves a the edge stencil and b the vertex stencil The position of the new control point clear diamond is computed by multiplying the original control points black discs by the associated fractions and summing the results There is a similar interpretation using stencils of the Lane Riesenfeld subdivision algorithm for bicubic B spline surfaces Topologically there are now three kinds of points face points edge points and vertex points To find the stencils for these points we need to find explicit formulas for the control points of the new control polyhedron after one level of subdivision We can calculate these points by taking two rounds of centroid averaging of the control points in Figure 4 The results are presented in Figure 18 0 o 9P013P023P11P12 3P01P029P113P12 9P113P123P21P22 16 16 16 31509Ib1Pm3P1l I1303P13Pm9Pl1 3 09 lPm3 n 16 16 16 9P00 3P01 3P10 P11 31000 P01 9P10 3P11 9P10 3P11 3on P21 16 16 16 a First round of centroid averaging P00 P10 6P01 6P11 P02 P12 P00 P20 6P01 6P10 36P116P21 6P12 P02 P22 64 P00P01P10P11 P00P016P10126P11P20P21 4 17 Second round of centroid averaging Figure 18 The control points for one level of subdivision of a uniform bicubic B spline surface constructed by applying two rounds of centroid averaging to the control points in Figure 4 As expected Figure 18 illustrates three kinds of stencils P P P P QF 00 01410 11 33 P00P106P016P11P02P12 16 34 P00P016P106P11P20P21 QE 16 QE P00P206P016Plo36P116P216P12P02P22 QV 35 64 Equation 33 represents the face stencil Equation 34 represents the two edge stencils one for vertical edges and one for horizontal edges and Equation 35 represents the vertex stencil We illustrate these stencils schematically in Figure 19 1 1 L 1 1 6 1 4 Z 16 1 6 4 64 6 6 6 6 36 6 0 1 1 6 4 64 6 4 1 1 1 1 6 1 4 4 16 1 6 4 64 6 4 a face stencil b edge stencil c vertex stencil Figure 19 Stencils for subdivision of bicubic B spline surfaces a face stencil b edge stencil and c vertex stencil The position of the new control point clear diamond is computed by multiplying the original control points black discs by the associated fractions and summing the results Note that there are two edge stencils one for horizontal edges and one for vertical edges Only the horizontal edge stencil is illustrated here since the vertical edge stencil is much the same except that the fractions 6 16 lie along horizontal edges instead of along vertical edges 15 322 Stencils for Extraordinary Vertices To extend stencils from uniform bicubic B spline surfaces to subdivision surfaces built from arbitrary quadrilateral meshes we need not alter the face stencil or the edge stencil all we need to do is to generalize the vertex stencil to extraordinary vertices This vertex stencil should be affine invariant the fractions should sum to one symmetric with respect to the surrounding vertices and reduce to the vertex stencil for bicubic B spline surfaces for ordinary vertices with valence four Also we want the stencil to generate smooth surfaces that is surfaces with at least one continuous derivative at the limits of the extraordinary vertices Two such stencils are provided in Figure 20 both satisfy all of our constraints but the Catmull Clark stencil tends to generate more rounded surfaces 167 6 16n 1 13 6 167 l 16n 167 27quot a simple vertax stencil b CatmullClark stencil Figure 20 Two vertex stencils for extraordinary vertices with valence n a a simple vertex stencil and b the Catmull Clark stencil Notice that both stencils reduce to the vertex stencil for bicubic B splines at ordinary vertices ie vertices where the valence n 4 see Figure 190 4 Triangular Meshes A triangular mesh is a collection of triangles where each pair of triangles are either disjoint or share a common edge and each edge belongs to at most two triangles Thus a triangular mesh is much like a quadrilateral mesh except that the faces are triangles instead of quadrilaterals A rectangular array of control points generates a regular quadrilateral mesh Splitting each face in this quadrilateral mesh along a fixed diagonal direction generates a regular triangular mesh a mesh where each interior vertex is adjacent to six vertices edges and faces The control points for the three direction box splines form a triangular mesh because the vector 11 splits each quadrilateral in the mesh generated by the control points into a pair of triangles Therefore three direction box splines are examples of surfaces generated by subdivision starting from a triangular mesh Triangular meshes are quite common in Geometric Modeling perhaps even more common than quadrilateral meshes Unlike the control points for three direction box splines the vertices of an arbitrary triangular mesh are not constrained to be generated from a rectangular array all that is 16 required is that the vertices can be joined into non overlapping triangular faces where each pair of faces are either disjoint or share a common edge and each edge belongs to at most two faces For example the faces of an octahedron form a triangular mesh even though the vertices of the octahedron do not form a regular mesh since in the octahedron each vertex has only four adjacent faces see Figure 24 Two additional examples of triangular meshes that are not regular are illustrated in Figure 23a and Figure 25 The goal of this section is to construct smooth surfaces via subdivision starting from triangular meshes of arbitrary topology We shall explore the same two paradigms for subdivision of triangular meshes that we investigated for quadrilateral meshes centroid averaging and stencils 41 Centroid Averaging for Triangular Meshes Three direction quartic box spline surfaces play the same basic role for subdivision algorithms of triangular meshes that uniform bicubic tensor product B spline surfaces play for subdivision algorithms of quadrilateral meshes Therefore we shall begin our investigation of subdivision algorithms for triangular meshes by taking another look at the subdivision algorithm for three direction quartic box splines 411 Three Direction Quartic Box Splines Much like the subdivision algorithm for uniform bicubic B spline surfaces the subdivision algorithm for three direction quartic box spline surfaces can be separated into two distinct stages topology and geometry In Section 2 we built the subdivision algorithm for one level of the three direction quartic box spline by averaging the control points generated by one level of the subdivision algorithm for the three direction piecewise linear box spline along the vectors 10 01 11 Computing the control points for the three direction piecewise linear box spline is equivalent to changing the topology of the mesh averaging these control points along the vectors 1 0 01 11 is equivalent to altering the geometry of the mesh In the topological stage we keep the original control points and we insert new control points at the midpoints of the edges of the triangular mesh see Figure 6 and Figure 22b Thus we alter the connectivity of the mesh adding new edges and faces by connecting the midpoints of adjacent edges Each edge is split into two edges and each face is split into four faces but as usual in the topological phase we do not alter the shape of the mesh In the geometric stage we reposition these control points by averaging the control points along the vectors 1 001 11 Thus in the geometric stage we change the shape of the mesh but we do not alter the connectivity of the vertices edges and faces see Figure 22c There is however another somewhat easier way to reposition the vertices We can generate the same points by applying the stencil in Figure 21 to the control points for the three direction piecewise linear box spline This result is easy to verify simply overlay the stencil in Figure 21 on 17 top of the points in Figure 6 and multiply As the stencil in Figure 21 moves through the array of control points in Figure 6 these products generate the points in Figure 7 see Exercise 4 0 1 1 8 8 1 2 1 8 8 39 1 1 8 0 Figure 21 A stencil for generating the control points for one level of subdivision for the three direction quartic box spline from the control points for one level of subdivision of the three direction piecewise linear box spline The point clear diamond at the center is repositioned by multiplying the points black discs and clear diamond by adjacent fractions and adding the results Serendipitously the stencil in Figure 21 can be decomposed into the average of six simpler stencils Indeed if we represent each stencil as a 3 X 3 matrix then we have the following identity 01 1 033 03 0 003 88 88 8 8 lilloioloiiloii 888 6 8 6 88 6 88 110 000 00 000 88 41 00 000 00 133 3301030 688 688 6 8 300 030 320 8 8 88 Equation 41 has a geometric interpretation Consider any interior vertex v in the triangular mesh generated by the subdivision algorithm for the three direction piecewise linear box spline Each of the six matrices on the right hand side of Equation 4 1 represents a stencil for one of the six triangles in the mesh with v as a vertex To reposition v for the three direction quartic box spline take the weighted centroid of each of these triangles with v assigned the weight 2 8 and the other two vertices assigned the weights 38 Then take the centroid of these weighted centroids see Figure 22c Note that unlike centroid averaging for bicubic B splines the triangle centroids are weighted centroids so we cannot reuse the same triangle centroids to reposition different vertices rather we must compute different weighted centroids for each triangle in order to reposition different vertices Despite this anomaly the advantage of this somewhat convoluted approach is that we can easily extend this technique to arbitrary triangular meshes even to triangular meshes with arbitrary topology 18 O O O I I I V a Original Control Points 17 New Topology c New Geometry Figure 22 One level of subdivision for the three direction quartic box spline In a we illustrate two faces of the original mesh In the topological stage 17 new control points yellow are inserted at the midpoints of the edges and new edges and faces are added to the mesh by connecting vertices along adjacent edges Thus each edge is split into two edges and each face is split into four faces In the geometric stage c each control point yellow or black is repositioned to the centroid blue of the weighted centroids green of the faces adjacent to the control point but the topology of the mesh is not changed Note that since the green centroids are weighted centroids we cannot reuse the same centroids to reposition different control points rather we must recompute these centroids for each vertex Compare to Figure 12 for bicubic B splines 412 Arbitrary Triangular Meshes As with three direction quartic box splines there are two main phases to centroid averaging for arbitrary triangular meshes topology and geometry To refine the topology of the mesh we proceed exactly as we did for three direction quartic box splines we keep the original vertices and we insert new edge vertices at the midpoints of the edges Thus each edge is split into two edges We also introduce new edges to connect the midpoints of adjacent edges and new faces surrounded by these new edges splitting each of the original faces into four faces see Figure 23b To alter the geometry of the mesh we reposition each vertex of the mesh to the centroid of the weighted centroids of the adjacent faces The only difference between subdivision for three direction quartic box splines and subdivision for arbitrary triangular meshes is that for arbitrary triangular meshes there need not be six faces adjacent to each interior vertex For example in the octahedron there are only four faces adjacent to each of the vertices An interior vertex of a triangular mesh where the number of adjacent faces edges or vertices is not equal to six is called an extraordinary vertex Again the number of faces edges or vertices adjacent to a vertex is called the valence of the vertex We can reposition each vertex Q in an arbitrary triangular mesh by the following rule Take the weighted centroid of each of the triangles containing Q with Q assigned the weight 28 and the other two vertices assigned the weights 3 8 then take the centroid of these weighted centroids Thus each vertex Q of the mesh is repositioned by the formula 1 1 Q gt E Ck 1 k1 where C1 C are the weighted centroids of the faces adjacent to Q and n is the valence of Q 19 After several levels of subdivision most of the interior vertices of a triangular mesh are ordinary vertices and the extraordinary vertices become more and more isolated because during the topological phase each face is subdivided into four faces by the edges joining the midpoints of the surrounding edges Thus the new edge vertices and the new face vertices all have valence six see Figure 23b so all the new vertices introduced by subdivision are ordinary vertices Also the valence of each of the original vertices is unchanged since the number of faces surrounding a vertex does not change during subdivision These results are analogous to similar results for quadrilateral meshes see Section 312 Hence during subdivision ordinary vertices remain ordinary vertices and extraordinary vertices remain extraordinary vertices with the same valence see Figure 23b Since all the new vertices have valence six locally the new triangular mesh looks exactly like a triangular mesh for a three direction quartic box spline surface only vertices from the original mesh that did not have valence six do not have six adjacent faces Therefore just like three direction quartic box spline surfaces the surfaces generated in the limit by iterating centroid averaging for triangular meshes have two continuous derivatives everywhere the only exceptions are at the limits of extraordinary vertices At the limits of extraordinary vertices these surfaces have only one continuous derivative except at the limits of extraordinary vertices of valence three where these limit surfaces are continuous but not necessarily differentiable see Warren and Weimer Chapter 8 a Extraordinary Vertex b New Topology c New Geometry Figure 23 One level of centroid averaging In a we illustrate eight faces of a triangular mesh surrounding an extraordinary vertex blue In the topological stage 17 new vertices yellow are inserted at the midpoints of the edges of the triangular mesh and new edges and faces are added to the mesh by joining the midpoints of adjacent edges In the geometric stage 0 each vertex blue yellow or black is repositioned to the centroid of the weighted centroids green of the faces adjacent to the vertex but the topology of the mesh is not changed Notice that all the new vertices yellow are ordinary vertices with valence six Also the extraordinary vertex blue at the center with valence eight remains an extraordinary vertex with valence eight and is repositioned to the centroid of eight adjacent weighted centroids green Since the green centroids are weighted centroids we cannot reuse the same centroids to reposition different vertices rather we must recompute these green centroids for each vertex Compare to Figure 13 for quadrilateral meshes 20 Figure 24 Three levels of centroid averaging applied to an octahedron left Notice the extraordinary vertices of valence four at the comers of the octahedron Figure 25 Centroid averaging applied to two tetrahedra meeting at a vertex The original triangular mesh is on the left the rst three levels of subdivision are illustrated successively on the right 42 Stencils for Triangular Meshes For bicubic Bspline surfaces and more generally for quadrilateral meshes of arbitrary topology we have seen that stencils provide an alternative to centroid averaging for generating smooth surfaces via subdivision Centroid averaging separates the computation of new vertices during subdivision into two phases topology and geometry After the insertion of new ver1ices in the topological phase all the vertices of the mesh are repositioned in the geometric phase by centroid averaging But centroid averaging is a bit cumbersome for three direction quartic box splines and more generally for triangular meshes of arbitrary topology because the centroids that must be averaged are weighted centroids Thus we need to compute a different weighted centroid for each triangle in order to reposition each vertex In contrast stencils allow us to compute the positions of all the new vertices in terms of the positions of the original 21 vertices without resorting to a different stencil for each vertex For regular triangular meshes all we need are a single edge stencil and a single vertex stencil For triangular meshes of arbitrary topology we shall also require additional stencils for extraordinary vertices Thus for three direction quartic box splines and more generally for triangular meshes of arbitrary topology stencils may be easier to implement than centroid averaging 421 Stencils for Three Direction Quartic Box Splines For three direction quartic box splines Figure 7 provides essentially two distinct explicit formulas for computing the new control points from the original control points after one level of subdivision 10031013111112 QET P 3P 3P P Q 00 108 11 21 31101111203121 QET P P P 10P P P P QV 00 01 10 11 12 21 22 16 Equation 42 represents the three edge stencils one for horizontal one for vertical and one for diagonal edges Notice that all three formulas are essentially the same Equation 43 represents the vertex stencil We illustrate these two stencils schematically in Figure 26 1 83978 1 3 839 a edge stencil b vertex stencil Figure 26 Stencils for subdivision of three direction quartic box splines a the edge stencil and b the vertex stencil The position of the new control point clear diamond is computed by multiplying the original control points black discs by the associated fractions and summing the results There are three edge stencils but they are all essentially the same so only the vertical edge stencil is shown here 422 Stencils for Extraordinary Vertices To extend stencils from three direction quartic box splines to subdivision surfaces built from arbitrary triangular meshes we need not alter the edge 22 stencil all we need to do is to generalize the vertex stencil to extraordinary vertices Similar to vertex stencils at extraordinary vertices of quadrilateral meshes this vertex stencil should be affine invariant the fractions should sum to one symmetric with respect to surrounding vertices and reduce to the stencil for three direction quartic box splines for vertices with valence six Also we want the stencil to generate smooth surfaces that is surfaces with at least one continuous derivative at the limits of the extraordinary vertices Two such stencils are provided in Figure 27 Both stencils satisfy all of our constraints but only the Loop stencil is guaranteed to generate surfaces with bounded curvatures a simple vertax stencil 1 Loop stencil Figure 27 Two vertex stencils for extraordinary vertices with valence n a a simple vertex stencil and b the Loop stencil For the Loop stencil 5 3 1 27 2 wn cos 8 8 4 n Notice that both stencils reduce to the vertex stencil for three direction quartic box splines at ordinary vertices ie vertices where the valence n 6 see Figure 26b 5 Summary Subdivision is an important tool in Geometric Modeling for several reasons i Subdivision algorithms allow us to replace complicated mathematical formulas with simple computational procedures ii Subdivision algorithms are easy to understand and simple to implement iii Subdivision algorithms can generate a large class of smooth functions iv Subdivision algorithms on polyhedral meshes can produce smooth shapes with arbitrary topology Thus subdivision provides a simple approach to generating a wide variety of smooth curves and surfaces This lecture presents three distinct paradigms for generating subdivision surfaces split and average box splines centroid averaging meshes of arbitrary topology and stencils vertex edge and face stencils as well as special stencils for extraordinary vertices Box spline surfaces are generalizations of uniform tensor product B spline surfaces constructed by a classical split and average approach to subdivision starting from a rectangular array of control points These box spline surfaces are important because they provide a paradigm for constructing subdivision algorithms for triangular meshes of arbitrary topology Indeed subdivision surfaces built by centroid averaging or by stencils starting from quadrilateral or triangular meshes of arbitrary topology are generalizations of standard subdivision procedures for bicubic tensor product B splines and three direction quartic box splines One of the big advantage of subdivision algorithms for polyhedral meshes is that unlike tensor product B spline or box spline schemes subdivision procedures for polyhedral meshes can generate smooth surfaces with arbitrary topology An important leitmotif of this chapter is that subdivision procedures can be partitioned into two separate phases refining the topology and altering the geometry that is changing connectivity and modifying shape For box splines we refine the topology by splitting each control point into four control points leaving the position of each control point unchanged For polyhedral meshes we refine the topology by inserting new vertices and edges and splitting each face into four faces leaving the positions of the original vertices unchanged In the geometric phase for box splines we alter the positions of the control points by averaging these points along prespecified directions in the plane of their integer indices In the geometric phase for polyhedral meshes we change the positions of the vertices by taking the centroid of the centroids of adjacent faces Stencils allow us to combine refining the topology and modifying the geometry of a polyhedral mesh into a single phase Below we summarize for easy access and comparison our three approaches to subdivision algorithms split and average centroid averaging and stencils for bicubic tensor product B splines and three direction quartic box splines surfaces defined over regular meshes whose subdivision algorithms serve as models for subdivision procedures on quadrilateral and triangular meshes of arbitrary topology We also review centroid averaging for quadrilateral and triangular meshes Finally we recall the stencils for extraordinary vertices in quadrilateral and triangular meshes 24 51 Bicubic Tensor Product BSplines and Three Direction Quartic Box Splines For bicubic tensor product B splines and three direction quartic box splines there are three approaches to subdivision algorithms split and average centroid averaging and stencils 511 Split and Average Split P2102 P231312 P2312141 P23812141 P13 3 Figure 28 Average Bicubic BSplines Piyl0 Pik LO kyo i1j I j 2 k 1 2 3 horizontal direction 3 k l 3 k l P P k 1 2 3 vertical direction Average Three Direction Quartic Box Splines 00 00 10 Pij Pi1j I horizontal direction 11 01 Pilf1 I 2 vertical direction k k k k P P l l ngy k k 1 2 diagonal direction P01 P01 P11 P11 P01 P01 P11 PM P00 P00 P10 PlO P00 P00 PlO Pro Figure 28 Splitting each control point into four points 25 512 Centroid Averaging Bicubic BSplines Refine the Topology P211321 Pi j Original Vertices P P P p P2114112 leiYZJH New Edge Vertices PP P P Pgimm New Face Vernm Modify the Geometry k l k l k l k l P P P P 1 HL 411 Hm k 2 3 Centroid Averaging I I f a Original Control Points b Re ned Topology c Centroid Averaging Figure 29 Centroid Averaging Bicubic B Splines First 17 refine the topology by placing new edge vertices at the center of each edge and new face vertices at the centroid of each face then connect these vertices with edges to split each face into four faces The new control point blue in c is repositioned to the centroid of the centroids green of the adjacent faces Three Direction Quartic Box Splines Refine the Topology Insert New Edge Vertices l P 212 j Pi j IijPi1j IijPij1 2 2 P1 P1 P1 Ply Pi1j1 2i12j 2132141 21412141 T Modify the Geometry Weighted Centroid Averaging 2 231 3Qk 3Qk1 g1 jvk 8 where Q1Q6 are the six vertices adjacent to Pg 2 2 2 2 2 2 P3 Pij1Pij2Pij3Pij4Iij5ij6 ij 6 26 O O O I I I V a Original Control Points 17 Re ned Topology c Centroid Averaging Figure 30 Centroid Averaging Three Direction Quartic Box Splines First 17 refine the topology by inserting a new edge vertex yellow at the center of each edge and then connecting vertices on adjacent edges to split each face into four faces The new control point blue in c is repositioned to the centroid of the weighted centroids green of the adjacent faces 513 Stencils Stencils represent explicit expressions in terms of the original control points for the new control points after one level of subdivision For bicubic B splines these formulas come in three basic forms expressions for face points expressions for edge points and expressions for vertex points For three direction quartic box splines these formulas come in only two basic forrns expressions for edge points and expressions for vertex points Bicubic BSplines P00P01P10P11 4 QFace P00P106P016P11P02P12 P00P016P106Pll P20P21 QEdge or 16 16 Q P00 P20 6P01 6P10 36P11 6P21 6P12 P02 P22 Vertex 64 1 1 L 1 1 6 1 4 4 16 16 64 64 64 g 6 6 36 6 O 16 16 64 64 64 1 1 1 1 1 6 1 4 16 1 6 4 64 64 a face stencil b edge stencil c vertex stencil Figure 31 Stencils for bicubic B splines a face stencil b edge stencil and c vertex stencil Three Direction Quartic Box Splines P003P013P11P12 P003P103P11P21 3P10P11P203P21 QEdge 8 or 8 or 8 P00P01P1010P11P12P21P22 QVerlex 16 27 m 5 aw 839 I 2 l l 1 1 l 39 3 1 8 8 16 12 a edge stencil b vertex stencil Figure 32 Stencils for Three Direction Quartic Box Splines a the edge stencil and b the vertex stencil 52 Centroid Averaging for Meshes of Arbitrary Topology a Extraordinary Vertex c Centroid Averaging Figure 33 Quadrilateral Meshes Each vertex is repositioned to c the centroid of the centroids blue of the adjacent faces after 17 refining the topology by splitting each quadrilateral face into four quadrilateral faces a Extraordinary Vertex b Re ned Topology c Centroid Averaging Figure 34 Triangular Meshes Each vertex is repositioned to c the centroid of the weighted centroids green of the adjacent faces after 17 refining the topology by splitting each triangular face into four triangular faces 28 53 Stencils for Extraordinary Vertices For quadrilateral meshes of arbitrary topology the edge and face stencils are the same as the edge and face stencils for tensor product bicubic B splines Similarly for triangular meshes the edge stencils are the same as the edge stencils for three direction quartic box splines Also for quadrilateral meshes the vertex stencil at regular vertices vertices with valence four is the same as the vertex stencil for tensor product bicubic B splines and for triangular meshes the vertex stencil at regular vertices vertices with valence six is the same as the vertex stencil for three direction quartic box splines Therefore for meshes of arbitrary topology we need only specify the vertex stencils at extraordinary vertices 167 167 1 13 6 167 1 16m 167 27quot a simple vertax stencil b CatmullClark stencil Figure 35 Quadrilateral Meshes Two vertex stencils for extraordinary vertices with valence n a a simple vertex stencil and b the Catmull Clark stencil a simple vertax stencil 1 Loop stencil Figure 36 Triangular Meshes Two vertex stencils for extraordinary vertices with valence n a a simple vertex stencil and b the Loop stencil For the Loop stencil 5 3 1 wn cos 8 8 4 n 29 Exercises 1 Let P17 be a rectangular array of control points a Show that averaging adjacent control points in the s direction and then averaging the resulting adjacent control points in the t direction is equivalent to rst averaging adjacent control point in the t direction and then averaging the resulting adjacent control points in the s direction by showing that in both cases the new control points are given by 3 Pi1j 3141 Pi1j1 Q13 b Generalize the result in part a by showing that averaging v adjacent points and then averaging w adjacent points is equivalent to first averaging w adjacent points and then averaging v adjacent points by showing that in both cases the new control points are given by 3 PiV1jV2 JiW1jW2 Q13 4 PiV1W1jV2W2 2 Consider the box spline surface generated by the control points Ply and the vectors V 1010 0101 11 a What is the degree of this surface b How smooth is this surface c Show that the control points for this surface after one level of subdivision are given by the array of points in Figure 37 d Using the result in part c derive the control points for three direction quartic box splines o 5P01PllP02PlZ P12PllPlZ 5P11P21P12P22 8 4 8 Rjo2P01Hl HOI10H15f11 P102P11P21 4 8 4 5P00PlOP01Pll W 5P10P20P11P21 8 4 8 Figure 37 The control points after one level of subdivision for the 3 direction box spline in Exercise 2 3 Consider the box spline surface generated by the control points Ply and the vectors V 1001 11 11 a What is the degree of this surface b How smooth is this surface c Show that the control points for this surface after one level of subdivision are given by the array of points in Figure 38 Figure 38 The control points after one level of subdivision for the 4 direction box spline in Exercise 3 A stencil S is called a universal stencil for a subdivision algorithm if all the control points face points edge points and vertex points after one level of subdivision can be generated by P022P01Pll 4 P00 2P01 1311 4 P01 21Ebo H0 4 P012PllPlZ P12 2P11 P21 4 4 P01 2H1P10 P102Pll 1321 4 4 P00 2H0H1 P112P10P20 4 4 sliding the stencil S over an array of points Q 4 Show that the stencil in Figure 21 is a universal stencil for the three direction quartic box spline by verifying that sliding this stencil on the array of control points in Figure 6 for one level of subdivision of the three direction linear box spline generates the control points in Figure 7 for one level of subdivision for the three direction quartic box spline 5 Consider the stencil in Figure 39 a Show that this stencil is a universal stencil for the uniform tensor product bicubic B splines by verifying that sliding this stencil on the array of control points in Figure 4 for one level of subdivision for bilinear B splines generates the control points in Figure 18b for one level of subdivision for bicubic B splines b Verify that if we represent this stencil as a 3 X 3 matrix then we have the following identity 1 2 16 16 2 4 16 16 L l 16 16 1W 1 16 4 2 11 16 44 L 0 16 1 1 oMHHH 4gt 4gtH4gtHo 04gtH4gt 4gtH4gtHo 0 0 01 0 4 0 0 4gtH4gtHo 4gtH4gtHo c Conclude from part b that after bilinear averaging each control point in the Lane Riesenfeld algorithm for a bicubic B spline is repositioned to the centroid of the centroids of the faces adjacent to the control point 2 1 16 1 16 g 4 2 1 16 16 1 1 16 2 E 16 Figure 39 A universal stencil for generating the control points for one level of subdivision for bicubic B splines from the control points for one level of subdivision for bilinear B splines The point clear diamond at the center is repositioned by multiplying the points black discs and clear diamond by the adjacent fractions and adding the results 6 Consider the stencil in Figure 40 a Show that this stencil is a universal stencil for cubic B spline curves by verifying that sliding this stencil along the array of control points in Figure 1 for one level of subdivision for the linear B splines generates the control points in Figure 16 for one level of subdivision for the cubic B splines b Show that this stencil can be decomposed into the average of two simpler stencils c Conclude from part b that after linear averaging each control point in the Lane Riesenfeld algorithm for a cubic B spline curve is repositioned to the midpoint of the midpoints of the edges adjacent to the control point 2 1 4 Figure 40 A universal stencil for generating the control points for one level of subdivision for cubic B spline curves from the control points for one level of subdivision for linear B spline curves The point clear diamond at the center is repositioned by multiplying the points black discs and clear diamond by the adjacent fractions and adding the results 7 Show that the stencil represented by the row vector 1 3 31 is a universal stencil for cubic B spline curves by verifying that sliding this stencil along the array where each of the original control points are doubled generates the control points for one level of subdivision for cubic B spline curves Generalize this result to B spline curves of arbitrary degrees 32 8 The Four Point Scheme Let E be a collection of control points and let Pl3 be the output of one level of the Lane Riesenfeld algorithm for cubic B spline curves Define one level of subdivision for the four point scheme by setting 0 3 3 3 4 i 14Pi Pi1 Pi Show that P interpolation 4 Z 9P3 9P31 P32 P2i1 fourpoint rule 16 Describe the edge stencil and vertex stencil for the four point scheme Find two distinct universal stencils for the four point scheme Using the result of part a conclude that the control polygons generated by iterating the four point scheme converge in the limit to curves that interpolates the original control points Implement the four point scheme Observe that the control polygons generated by this subdivision algorithm converge in the limit to smooth curves 9 Verify that the Loop stencil in Figure 27b reduces to the vertex stencil for the three direction quartic box spline in Figure 26b when the valence n 6 Programming Projects 1 Box Splines Implement subdivision for box spline surfaces in your favorite programming language using your favorite API a b Render bicubic B splines and four direction quartic box splines using your favorite shading algorithm and hidden surface procedure Build some interesting freeform shapes using box spline surfaces 2 Quadrilateral Meshes Implement subdivision algorithms for quadrilateral meshes in your favorite programming language using your favorite API a b 0 Include both centroid averaging and Catmull Clark stencils at extraordinary vertices Render these subdivision surfaces using your favorite shading algorithm and hidden surface procedure Build some interesting freeform shapes of arbitrary topology using subdivision algorithms for quadrilateral meshes of arbitrary topology 33 Triangular Meshes Implement subdivision algorithms for triangular meshes in your favorite programming language using your favorite API a b 0 Include both centroid averaging and Loop stencils at extraordinary vertices Render these subdivision surfaces using your favorite shading algorithm and hidden surface procedure Build some interesting freeform shapes of arbitrary topology using subdivision algorithms for triangular meshes of arbitrary topology Split and Average Geometric Mean Let Pk xkyk be a collection of points in the xy plane where y k gt 0 and consider the following variation of the Lane Riesenfeld algorithm 9 0 Replace midpoint averaging for the y coordinate by the geometric average that is replace the quot quot mean yk Zyk by the mean y k y k1 but use the arithmetic xk X mean A for averaging the x coordrnates Thus the new averaging rule is Xk Xk 1 VPkaPk1 IYkYkHJ Implement this new subdivision algorithm i Are the curves you construct always smooth ii Compare these new curves to the curves generated by the standard Lane Riesenfeld algorithm for linear quadratic and cubic B splines with the same control points Now replace midpoint averaging in the x coordinate by the geometric mean but use the arithmetic mean in the y coordinate i Are the curves still smooth How are these curves related to the curves generated by the standard Lane Riesenfeld H H algorithm for linear quadratic and cubic B splines with the same control points H H H 39 How are these curves related to the curves generated in part a Lecture 4 Af ne Transformations for Satan himself is transformed into an angel of light 2 Corinthians 1114 1 Transformations Transformations are the lifeblood of geometry Euclidean geometry is based on rigid motions translation and rotation transformations that preserve distances and angles Congruent triangles are triangles where corresponding lengths and angles match Transformations generate geometry The turtle uses translation FORWARD rotation TURN and uniform scaling RESIZE to generate curves by moving about on the plane We can also apply translation SHIFT rotation SPIN and uniform scaling SCALE to build new shapes from previously de ned turtle programs These three transformations translation rotation and uniform scaling are called conformal transformations Conformal transformations preserve angles but not distances Similar triangles are triangles where corresponding angles agree but the lengths of corresponding sides are scaled The ability to scale is what allows the turtle to generate self similar fractals like the Sierpinski gasket In Computer Graphics transformations are employed to position orient and scale objects as well as to model shape Much of elementary Computational Geometry and Computer Graphics is based upon an understanding of the effects of different fundamental transformations The transformations that appear most often in 2 dimensional Computer Graphics are the affine transformations Af ne transformations are composites of four basic types of transformations translation rotation scaling uniform and non uniform and shear Af ne transformations do not necessarily preserve either distances or angles but af ne transformations map straight lines to straight lines and af ne transformations preserve ratios of distances along straight lines see Figure 1 For example affine transformations map midpoints to midpoints In this lecture we are going to develop explicit formulas for various affine transformations in the next lecture we will use these affine transformations as an alternative to turtle programs to model shapes for Computer Graphics AR Q i b39 a a A P Aw Q Figure 1 An af ne transformation A maps lines to lines and preserves ratios of distances along straight lines Thus AQ lies on the line joining AP and AR and a39 b a b A word of warning before we begin There is a good deal of linear algebra in this chapter Don t panic Though there is a lot of algebra the details are all fairly straightforward The bulk of this chapter is devoted to deriving matrix representations for the affine transformations which will be used in subsequent chapters to generate shapes for 2 dimensional Computer Graphics All the matrices that you will need later on are listed at the end of this chapter so you will not have to slog through these derivations every time you require a specific matrix you can find these matrices easily whenever you need them Persevere now because there will be a big payoff shortly 2 Conformal Transformations Among the most important affine transformations are the conformal transformations translation rotation and uniform scaling We shall begin our study of affine transformations by developing explicit matrix representations for these conformal transformations To fix our notation we will use upper case letters PQR from the middle of the alphabet to denote points and lower case letters uv w from the end of the alphabet to denote vectors Lower case letters with subscripts will denote rectangular coordinates Thus for example we shall write P p1p2 to denote that p1p2 are the rectangular coordinates of the point P Similarly we shall write v v1 v2 to denote that v1v2 are the rectangular coordinates of the vector v 21 Translation We have already encountered translation in our study of Turtle Graphics see Figure 2 To translate a point P p1p2 by a vector w W1 wz we set PW P w 1 or in terms of coordinates new P1 P1 W1 new P2 P2 W2 Vectors are unaffected by translation so new v v We can rewrite these equations in matrix form LetI denote the 2 X 2 identity matrix then Pnew P I w vnewvI W V Vnew P W Pnew Figure 2 Translation Points are affected by translation vectors are not affected by translation 2 22 Rotation We also encountered rotation in Turtle Graphics Recall from Lecture 1 that to rotate a vector v v1v2 through an angle 0 we introduce the orthogonal vector vi v2v1 and set vnew cos 0v sin0vJ or equivalently in terms of coordinates vlnew v1 cos0 v2 sin0 2 vgew v1 sin0 v2 cos0 Introducing the rotation matrix cos0 sin0 Rome sin0 cos0 we can rewrite Equation 2 in matrix form as vnew v R0t0 3 In our study of affine geometry in the plane we want to rotate not only vectors about their tails but also points about other points Since P Q P Q rotating a point P about another point Q through the angle 0 is equivalent to rotating the vector P Q through the angle 0 and then adding the resulting vector to Q see Figure 3 Thus by Equation 3 the formula for rotating a point P about another point Q through the angle 0 is PW Q P Q R0t0 P R0t0 Q 1 R0t0 4 where I is again the 2 X 2 identity matrix Notice that if Q is the origin then this formula reduces to PW P R0t0 so R0t0 is also the matrix representing rotation of points about the origin Figure 3 Rotation about the point Q Since the point Q is fixed and since P Q P Q rotating a point P about the point Q through the angle 0 is equivalent to rotating the vector P Q through the angle 0 and then adding the resulting vector to Q 3 23 Uniform Scaling Uniform scaling also appears in Turtle Graphics To scale a vector v v1 v2 by a factor 3 we simply set new v sv 5 or in terms of coordinates new v1 svl vgew svz Introducing the scaling matrix s 0 Scales 0 j s we can rewrite Equation 5 in matrix form as vnew v Scales Again in affine geometry we want not only to scale vectors but also to scale uniformly the distance of points from a fixed point Since P Q P Q scaling the distance of an arbitrary point P from a xed point Q by the factor 3 is equivalent to scaling the length of the vector P Q by the factor 3 and then adding the resulting vector to Q see Figure 4 Thus the formula for scaling the distance of an arbitrary pointP from a fixed point Q by the factor 3 is PW Q P Q Scales P Scales Q 1 Scales 6 Notice that if Q is the origin then this formula reduces to PW P Scales so Scales is also the matrix that represents uniformly scaling the distance of points from the origin Pnew Figure 4 Uniform scaling about a fixed point Q Since the point Q is fixed and since P Q P Q scaling the distance of a point P from the point Q by the factor 3 is equivalent to scaling the vector P Q by the factor 3 and then adding the resulting vector to Q 3 The Algebra of Affine Transformations The three conformal transformations translation rotation and uniform scaling all have the following form there exists a matrix M and a vector w such that vnew v M new P P M w In fact this form characterizes all affine transformations That is a transformation is said to be affine if and only if there is a matrix M and a vector w so that Equation 7 is satis ed The matrix M represents a linear transformation on vectors Recall that a transformation L on vectors is linear if Lu v Lu Lv 1a cLv 8 Matrix multiplication represents a linear transformation because matrix multiplication distributes through vector addition and commutes with scalar multiplication that is uvMuMvM cv M cv AI The vector w in Equation 7 represents translation on the points Thus an affine transformation can always be decomposed into a linear transformation followed by a translation Notice that adding a constant vector to a vector is not a linear transformation since adding a constant vector does not satisfy Equation 8 see Exercise 1 Therefore translation cannot be represented by a 2 X 2 matrix Af ne transformations can also be characterized abstractly in a manner similar to linear transformations A transformation A is said to be affine if A maps points to points A maps vectors to vectors and Au v Au Av Ac v c Av 9 AP v AP Av The first two equalities in Equation 9 say that an af ne transformation is a linear transformation on vectors the third equality asserts that affine transformations are well behaved with respect to the addition of points and vectors You should check that with this de nition translation is indeed an affine transformation In terms of coordinates linear transformations can be written as new 6 ax by new new a 0 new gt x y xy 10 y c x d y b d whereas affine transformations have the form new 6 axbye new new a c ltgt 36 y xy 8f 11 y ewcxdyf b d The constant terms 8 and f that appear in Equation 11 are what distinguish the affine transformations of Computer Graphics from the linear transformations of classical linear algebra These constants represent translation which as we have seen is not a linear transformation 4 The Geometry of Af ne Transformations There is also a geometric way to characterize both linear and affine transformations Interpreted geometrically Equation 8 says that linear transformations map triangles into triangles and lines into lines see Figure 5 Moreover linear transformations preserve ratios of distances along lines since w M M M M39 L M Lv V gtL CV Lc v c Lv L I v Lv MV Luv LuLv Figure 5 Linear transformations map triangles into triangles left and lines into lines right Similarly interpreted geometrically Equation 9 makes precisely the same assertions about affine transformations extending these results to points as well as to vectors see Figure 6 P v AP v AP Av A 140 P AP Figure 6 Af ne transformations map triangles into triangles and lines into lines Figure 5 and these results are consistent for points as well as for vectors 5 Affine Coordinates and Affine Matrices Linear transformations are typically represented by matrices because composing two linear I transformations is 1 39 to J39 the cor matrices We would like to have the I 1 same facility with af ne transformations that is we would like to be able to compose two affine transformations by multiplying their matrix representations Unfortunately our current representation of an affine transformation in terms of a transformation matrix M and a translation vector w does not work so well when we want to compose two affine transformations In order to overcome this dif culty we shall now introduce a clever device called affine coordinates Points and vectors are both represented by pairs of rectangular coordinates but points and vectors are different types of objects with different behaviors for the same affine transformations For example points are affected by translation but vectors are not We are now going to introduce a third coordinate an affine coordinate to distinguish between points and vectors Af ne coordinates will also allow us to represent each affine transformation using a single 3X 3 matrix and to compose any two af ne transformations by matrix multiplication Since points are affected by translation and vectors are not the affine coordinate for a point is 1 the affine coordinate for a vector is 0 Thus from now on we shall write P p1 1721 for points and v v1 v2 0 for vectors Affine transformations can now be represented by 3 X 3 affine matrices An affine matrix is a 3 X 3 matrix where the third column is 0 0 1T The affine transformation vnew v M Pnew P M w represented by the 2X 2 transformation matrix M and the translation vector w can be rewritten using af ne coordinates in terms of a single 3 X 3 affine matrix M 0 M 0 1 VW 0v0Mv0M VM 0 W Now new P 1 P1MP1 1 PMw 1 W Notice how the affine coordinate 0 for vectors and 1 for points is correctly reproduced by multiplication with the last column of the matrix M Notice too that the 0 in the third coordinate for vectors effectively insures that vectors ignore the translation represented by the vector w 6 Conformal Transformations Revisited To illustrate some specific examples of affine matrices below we show how to represent the standard conformal transformations translation rotation and uniform scaling in terms of 3 X 3 affine matrices These results follow easily from Equations 1 4 and 6 Translation by the vector w W1 wz Transw1 0 1 0i 0 l Lwl W2 1i Rotation around the Origin through the angle 0 I I Rome cos0 sin0 0W Rot0rigin 0 0 1 L s1n0 cos0 0 0 0 1i Rotation around the point Q 611612 through the angle 0 Rotm 0 cos 0 sin 0 0W RotQ0 QI Rome 1 s1n0 I I cos0 0 6111 cos0 qz s1n0 q1s1n0 q21 cos6 1 Uniform Scaling around the Origin by the factor 3 s 0 0 SI 0 Scale0rigins 0 1 0 s 0 looll Uniform Scaling around the point Q 611612 by the factor 3 s 0 0W SI 0 ScaleQ s Q 1 S I 0 s 0 LG sq1 1 Sq2 1i 7 General Affine Transformations We shall now develop 3X 3 matrix representations for arbitrary af ne transformations The two most general ways of specifying an affine transformation of the plane are by specifying either the image of one point and two linearly independent vectors or by specifying the image of three non collinear points We shall treat each of these cases in turn 8 71 Image of One Point and Two Vectors Fix a point Q and two linearly independent vectors uv Since two linearly independent vectors uv form a basis for vectors in the plane for any vector w there are scalars c7 7 such that w a u T v Hence for any point P there are scalars st such that P Q su tv or equivalently P Q su tv Therefore if A is an affine transformation then by Equation 9 AP AQ sAu tAv Aw OAu 1Av Thus if we know the effect of the affine transformation A on one point Q and on two linearly independent vectors uv then we know the effect of A on every point P and every vector w Hence 12 in addition to conformal transformations there is another important way to define affine transformations of the plane by specifying the image of one point and two linearly independent vectors Geometrically Equation 12 says that an affine transformation A maps the parallelogram determined by the point Q and the vectors uv into the parallelogram determined by the point AQ and the vectors AuAv see Figure 7 Thus affine transformations map parallelograms into parallelo grams P AP W l v Agt Av l 140 V 4 A Q u su AW sAu Figure 7 Af ne transformations map parallelograms into parallelograms To find the 3 X 3 matrix representation M for such an affine transformation A let Q 14 v be the images of Q u v under the transformation A Then using affine coordinates we have u0 140 M v 0 v0 M Q1Q1M where M Le 1 Thus 14 O u OWrac 0 vquot o v o b d o 91 l9 f 1l ram ref 1 Sum Sam M Solving for M yields 1 MSald5new orequivalently r14 0 1 14 O 141 142 0T1 MT 14 O Mvov0v1v20va 0 13 LQ 1i Qquot 1 in In 1J qi q 1 To compute M explicitly we need only invert a 3x 3 affine matrix But for a nonsingular 3x 3 affine matrix the inverse can easily be written explicitly for the formula see Exercise 13a An alternative explicit formula for the matrix M without inverses is provided in Exercise 21 72 NonUniform Scaling One application of our preceding approach to general affine transformations is a formula for nonfuniform scaling Uniform scaling scales distances by the same amount in all directions nonfuniform scaling scales distances by different amounts in different directions We are interested in nonfuniform scaling for many reasons For example we can apply nonfuniform scaling to generate an ellipse by scaling a circle from its center along a fixed direction see Figure 8 To scale the distance from a fixed point Q along an arbitrary direction w by a scale factor X we shall now apply our method for generating arbitrary affine transformations by specifying the image of one point and two linearly independent vectors see Figure 9 Figure 8 Scaling a circle from its center along a fixed direction generates an ellipse l O Q Q Figure 9 Scaling from the xed point Q in the direction w by the scale factor 3 The point Q is J xed the vector w is scaled by s and the orthogonal vector w remains fixed Thus non uniform scaling maps a square into a rectangle Let ScaleQws denote the matrix that represents the affine transformation which scales the distance from a fixed point Q along an arbitrary direction w by a scale factor 3 To nd the 3 X 3 matrix ScaleQ w s we need to know the image of one point and two linearly independent vectors J Consider the point Q and the vectors w and wJ where w is a vector of the same length as w perpendicular to w It is easy to see how the transformation ScaleQ ws affects Q w wJ Q gt Q because Q is a fixed point of the transformation 0 w gt sw because distances are scaled by the factor 3 along the direction w wJ gt wJ because distances along the vector wJ are not changed since wJ is orthogonal to the scaling direction w Therefore by the results of the previous section w 0Y1 SW 0W J J ScaleQws w 0 w 0 l Q J lg J Now recall that if w wlw2 then wJ w2w1 Therefore in terms of coordinates W1 wz 0Y1 SW1 swz 0W ScaleQws w2 W1 0 w2 W1 0 i J L 11 12 J qr 12 1 An explicit formula for the matrix ScaleQ w 3 without inverses is provided in Exercise 20 If Q is the origin and w is the unit vector along the x axis then wJ is the unit vector along the y axis so W1 w2 0 r 1 0 0W w2 W1 0 0 1 0 IdentilyMatrix q1 q2 1 0 0 1 Therefore scaling along the x axis is represented by the 3 X 3 matrix 300W Scale0riginis 0 1 0 0 0 1 Similarly scaling along the y axis is represented by the 3 X 3 matrix 1 0 0W Scale0rigin j s 0 s 0 i0 0 1J 73 Image of Three NonCollinear Points If we know the image of three non collinear points under an affine transformation then we also know the image of one point and two linearly independent vectors Indeed suppose that we know the image of the three non collinear points P1P2P3 under the affine transformation A Then u P2 P1 and v P3 P1 are certainly linearly independent vectors and Au AP2 P1 AP2AP1 Mquot AP3 P1 AP3 AP1 Hence if we know the image of P1P2P3 under the affine transformation A then we know the image of the point P1 and the two linearly independent vectors uv Therefore the image of three non collinear points specifies a unique affine transformation To find the 3 X 3 matrix M that represents an affine transformation A defined by the image of three non collinear points we can proceed as in Section 71 Let P1P2P3 be the images of the points P1P2P3 under the affine transformation A Using affine coordinates we have Pf1P11 M P321 P21 M P 1 P31 M where a c 0W M b d 0 e f IJ Thus P1 1 P1 1W a c 0W P2 1P2 d P 1 1P 11 L f 11 WT PmW Pold Solving for M yields MP0 IIPnew or equivalently if Pk xkyk and P x1 y for k 123 then P111 P11 x1y111 xf yf 1 MP21P21x2y21x y 1 14 i103 J P 1 i953 Y3 J x y 1 To compute M explicitly we need only invert a 3X 3 matrix whose last column is 1 1 1T This inverse can easily be written explicitly for the formula see Exercise 13b An alternative explicit formula for the matrix M without inverses is provided in Exercise 21 Notice the similarity between the right hand side of Equation 14 and the right hand side of Equation 13 in Section 71 for the matrix representing the affine transformation defined by the image of one point and two linearly independent vectors The only differences are the ones appearing in the first two rows of the third columns indicating that two vectors have been replaced by two points 8 Summary Below is a brief summary of the main high level concepts that you need to remember from this lecture Also listed below for your convenience are the 3X3 matrix representations for all the affine transformations that we have discussed in this lecture 81 Af ne Transformations and Af ne Coordinates Affine transformations are the fundamental transformations of 2 dimensional Computer Graphics There are several different ways of characterizing affine transformations 1 A transformation A is affine if there exists a 2 X 2 matrix M and a vector w such that Av v M AP P M w 2 A transformation A is affine if there is a 3 X 3 affine matrix M such that Av 0 v 0 M AP1 P 1 M 3 A transformationA is affine if Au v Au Av Ac v c Av AP v AP Av 4 A transformationA is affine if A maps triangles to triangles and lines to lines andA preserves ratios of distances along lines Affine transformations include the standard conformal transformations translation rotation and uniform scaling of Turtle Graphics but affine transformations also incorporate other transformations such as non uniform scaling Every affine transformation can be uniquely specified either by the image of one point and two linearly independent vectors or by the image of three non collinear points Affine coordinates are used to distinguish between points and vectors The affine coordinate of a point is 1 the affine coordinate of a vector is 0 Affine coordinates can be applied to represent all affine transformations by 3 X 3 matrices of the form M M 0 w 1 v ww 0 v0 M P ew1P1M so that These matrix representations allow us to compose affine transformations using matrix multiplication The affine transformations of Computer Graphics are closely related to the linear transformations of standard linear algebra In fact in terms of matrix representations Linear 0W Affine Transformation LTransformation OJ Translation 1 In Table 1 we provide a more detailed comparison of the differences between affine and linear transformations Af ne Transformation Linear Transformation Au v Au Av Lu v Lu Lv Acv c Av 0 v c Lv AP v AP Av Includes Translation Excludes Translation Affine Coordinates Rectangular Coordinates Coordinate Formulas Coordinate Formulas xnew axold byold e xnew axold byold Ynew cxold dyold f ynew cxold dyold 3 X 3 Matrix Representation 2 X 2 Matrix Representation a c 0W a c xnewynew 1xoldyold 1kb d OJ xnewynewxold yoldb 51 e f 1 Table 1 Comparison of affine and linear transformations For both affine and linear transformations composition of transformations is equivalent to matrix multiplication Finally a word of caution before we conclude We use matrices to represent transformations but matrices are not the same things as transformations Matrix representations for affine transformations are akin to coordinate representations for points and vectors that is a low level computational tool for communicating efficiently with a computer Matrices are the assembly language of transformations As usual we do not want to think or write programs in an assembly language we want to work in a high level language In the next lecture we shall introduce a high level language for 2 dimensional Computer Graphics based on affine transformations You will code the matrices for these transformations only once but you will use the corresponding high level transformations many many times 82 Matrices for Affine Transformations in the Plane Translation by the vector w W1 wz Transw 0 1 1 1 W1 W2 1 Rotation around the Origin through the angle 0 Rome 0 cos sin0 0 s1n0 cos0 0 0 1 k 0 0 1J RotOrigin 0 Rotation around the point Q 611612 through the angle 0 Rotm 0 cos 0 sin 0 0W RotQ 0 Q I Rome 1 s1n0 I I cos0 0 6111 cos0 qz s1n0 q1s1n0 q21 cos6 1 Uniform Scaling around the Origin by the factor 3 s 0 0W SI 0 ScaleOriginqs0 I 0 s 0 lo 0 1J Uniform Scaling around the point Q 61142 by the factor 3 r s 0 0W SI 0 ScaleQ s j 0 s 0 Q 1 s1 1 LG sq1 1 Sq2 1 Non Uniform Scaling around point Q 611612 in direction w W1 wz by the factor 3 W1 wz 0 1 SW1 swz 0W ScaleQws w2 W1 0 w2 W1 0 km 12 J LA 12 J Scaling from the Origin along the xaxis by the factor 3 r s 0 0W ScaleOrigin is 0 1 0 L0 0 I Scaling from the Origin along the yaxis by the factor 3 1 0 0W ScaleOrigin j s 0 s 0 lo 0 1J Image 0f0ne Point Q X3y3 and Two Vectors v1 x1y1 v2 x2y2 1 x1 Y1 0 3 1 Y1 0 Imagev1v2Qgt x2 Y2 0 x y 0 1x3 Y3 11 x Y 1 Image of Three NonCollinear Points P1 x1y1 P2 x2y2 P3 X3y3 x1 Y1 1 1 x1 Y1 1 ImageP1aP2P3 x2 Y2 1 x Y 1 1x3 Y3 11 x Y 1 Inverses Y2 Y1 0 x1 Y1 0Y1 xz X1 0 x2 y2 0 x2Y3 Y2x3 Y1x3 x1Y3 x1Y2 Y1x2 X1Y2 Y1x2 1x3 Y3 1 Y2Y3 Y3 Y1 Y1 Y2 x 1 263 262 261 263 262 261 J 1 x2Y3 Y2x3 Y1x3 x1Y3 x1Y2 Y1x3 1x3 yg J X1 Y2 Y3 x2Y3 Y1 x3Y1 Y2 Exercises 1 Define Lwv v w and TWP P w Show that lwv is not a linear transformation on vectors but that Tw P is an af ne transformation on points 2 Show that the formula for scaling a point P around a point Q by a scale factor 3 is equivalent to new P 1 sQsP 3 Let wQ denote the vector from the origin to the point Q Without appealing to coordinates and without explicitly multiplying matrices explain why i R0tQ 0 Trans WQ R0t0 TranswQ ii ScaleQ s Trans WQ Scales TranswQ Hint Give a geometric interpretation for formulas i and ii 17 4 Let wQ denote the vector from the origin to the point Q let i denote the unit vector along the x axis and let 0 denote the angle between the vectors i and w Without appealing to coordinates and without explicitly multiplying matrices show that ScaleQ ws Trans WQ Rom x Scale0rigin i s Rotx TranswQ Hint Give a geometric interpretation for this formula 5 Show that rotation and scaling about a xed point commute That is show that R0tQ 0 ScaleQ s Scale Q s R0tQ 0 6 Verify that if w W1 wz then wJ w2w1 by invoking the formula wi wR0t7r2 7 What is the geometric effect of the transformation matrix w 0Y1 sw 0W wJ 0 th 0 l Q J l Q J 8 Show that when affine transformations are represented by 3 X 3 matrices composition of affine transformations is equivalent to matrix multiplication 9 Let A be an affine transformation Using Equation 9 show that for all points PQ AQ P AQ AU 10 Let M be the 3 X 3 affine matrix that represents the affine transformation A Show that Ai 0W M A j 0 iA0rigin Ii 1 1 Show that a the composite of two affine transformations is an affine transformation b the inverse of a nonsingular affine transformation is an affine transformation Conclude that the nonsingular affine transformations form a group 12 Let MN be two matrices whose third column is 0 0 1T Show that a the third column of M N is 0 0 1T b the third column of M 1 is 0 0 1T Conclude that the nonsingular affine matrices form a group 18 13 Verify that M a M 262 L953 351 b M X2 L953 14 a Y1 YZ YS Y1 YZ YS Y2 Y1 0 x x 0 0W 2 1 x x x x x x 0 gt M 1 2Y3 Y2 3 Y1 3 1Y3 1Y2 Y1 2 I x1Y2 Y1x2 Y2Y3 Y3Y1 Y1 Y2 1W 953 x2 951 x3 x2 x1 x x x x x x 1 gt M 1 2Y3 Y2 3 Y1 3 1Y3 1Y2 Y1 2 J X1CY2 Y3 x2Y3 Y1 x3Y1 Y2 Show that an affine transformation is uniquely determined by the image of two points and one vector that is not parallel to the line determined by the two points b Let P1P2 11 be the images of P1P2 v under the affine transformationA Find the 3 X 3 matrix M that represents the affine transformation A 15 Show that every conformal transformation is uniquely determined by a the image of one point and one vector b the image of two points 16 Show that if M is a conformal transformation then ScaleFactorUM ldet1I 17 Let Mirr0rQw denote the matrix representing the transformation that mirrors points and vectors in the line determined by the point Q and the direction vector w a Show that i Mirr0rQw kw 1w 3111 w 31 13 J ScaleQ wJ 1 Q J b Conclude that the matrices representing mirroring in thex and y axes are given by 1 ii Mirr0r0rigini 0 1 0 lo 0 1 iii Mirr0r0riginj 0 0W H GHQ 00 4 0 0 18 Shear is the affine transformation defined by mapping a unit square with vertex Q and sides wwJ into a parallelogram by tilting the edge wJ so that wife makes an angle of 0 with wJ see Figure 10 Show that P O 0 1 ShearQwwJ 0 WWJ tan01wi 1 Q Q 1 r 1 0 0W Shear0riginij0 tame 1 0 L 0 0 11 detShearQwWJ 9 1 Shear preserves area 1 1 szw w gt Q quot 7 Q W W Figure 10 Shear maps the rectangle with vertex Q and sides w wJ into a parallelogram by tilting the edge wJ so that wife makes an angle of 0 with wi 19 Show that every nonsingular affine transformation is the composition of 1 translation 1 rotation 1 shear and 2 non uniform scalings a 20 Fix a vector w and a scalar 3 Define Av v s 1 v W w where v 39w v1w1 vzwz w 39 w Show that i Aw SW 0 ii AwJ wJ iii v aw wi gt Avsaw wi Conclude from part a that v 39 w iv vScaleQwsvs 1 w w 39 w Using the result of part b show that for every point P P Q 39 W w w 39 w 20 v P ScaleQws P s 1 d Using the results of parts 170 show that s lw12 s lw1w2 1 2 2 2 2 0 W1 W2 W1 W2 1 1 2 vi ScaleQws 22 1 0 W1 W2 W1 W2 5 1X 11Wf q2W1W2 S 1q1W1W2 q2W2 1 L W12 w W12 w J 21 Fix 6 points P1P2P3 and P1P2P3 expressed in affine coordinates and de ne DetRT Pf P3TP1DetP1T RT P3T P DetP1T P RTP3 AR DetP1T Pf P3T a Show that APl Pf i123 b Using part a show that the 3 X 3 matrix representing the affine transformation that maps the points P1P2P3 to the points P1P2P3 is given by P2XP3T P1 P3XP1T P2P1XP2T P ImagePiaP2P3 DetP1T Pf P3T 22 In this exercise we are going to prove that for every triangle up to sign P1 1 x1 Y1 1 AreaAP1P2P3 i deIL P2 IJ i dethz yz IJ 15 P3 1 X3 y3 1 a Verify that Equation 15 is valid if P1 is at the origin and P2 lies on the x axis b Show that for any AP1P2P3 there is a rigid rnotionR consisting of a rotation followed by a translation that maps AP1P2P3 to AQ1Q2Q3 where Q1 is the origin and Q2 is a point on the x axis c Show that i AreaAP1P2P3 AreaAQ1Q2Q3 191 1 P1 11 11 detLg U detLi d Conclude from parts abc that Equation 15 is valid for every triangle 21 23 Prove in two ways that nonsingular affine transformations preserve ratios of areas a by using the fact that nonsingular transformations preserve ratios of distances along lines b by invoking Equation 15 24 Let P1P2P3 be 3 non collinear points a Show that for each point P there exist unique scalars 31 32 33 such that i P31P1 2P2 3P3 ii 31 B2 B3 1 The values 32 33 are called the barycentric coordinates of P with respect to AP1P2P3 b Using Equation 15 and standard properties of determinants show that up to sign area APPP iii Bk ij k see Figure 11 areaAP1P2P3 P3 P1P 2 Figure 11 The barycentric coordinates of the point P relative to AP1P2P3 25 Let P1P2P3 be 3 non collinear points and let B1 2 3 be the barycentric coordinates of P with respect to AP1P2P3 see Exercise 24 a Show that if A is an affine transformation then AP B1AP1 B2AP2 33 AP3 b Conclude that the barycentric coordinates of AP with respect to AAP1AP2AP3 are identical to the barycentric coordinates of P with respect to AP1P2P3 see Figure 12 P3 AP3 Agt P1 A P2 AP1 I33 AP AP2 Figure 12 Affine transformations preserve barycentric coordinates 22 Lecture 25 Bezier Subdivision And he took unto him all these and divided them in the midst and laid each piece one against another Genesis 1510 1 Divide and Conquer If we are going to build useful computer models of freeform shapes using Bezier curves and surfaces we need procedures to do more than simply evaluate points along these curves and surfaces We need algorithms to analyze their geometry For example to ray trace a Bezier patch we need algorithms both for finding surface normals and for computing ray surface intersections In Lecture 24 we developed an algorithm for differentiating Bezier curves and surfaces which allows us to find the surface normal of a Bezier patch at any parameter value by taking the cross product of the partial derivatives of the patch Here we shall develop an algorithm that will permit us to compute the intersection of an arbitrary ray with a Bezier patch The method we shall employ is a divide and conquer technique called Bezier subdivision The main idea behind Bezier subdivision is that although globally Bezier curves and surfaces represent curved shapes if we divide these curves and surfaces into a collection of small enough segments each segment will be almost flat Flat shapes like lines and planes are simple to analyze For example we can easily ray trace a planar polygon Thus we shall analyze Bezier curves and surfaces by dividing these curves and surfaces into lots of small at segments analyzing the individual at segments and then recombining the results to build an understanding of the global geometry of the entire curve or surface Bezier subdivision is a powerful tool with many applications In this lecture we shall use Bezier subdivision to develop fast robust algorithms for rendering and intersecting Bezier curves and surfaces We shall also use Bezier subdivision to prove the variation diminishing property for Bezier curves and to show how to connect two Bezier curves smoothly at their join 2 The de Casteljau Subdivision Algorithm The control points of a Bezier curve describe a polynomial curve with respect to a fixed parameter interval a 17 Sometimes however we are interested only in the part of the polynomial curve in a subinterval of a b For example when rendering a Bezier curve we may need to clip the curve to a window on the graphics terminal Since any segment of a Bezier curve is itself a polynomial curve we should be able to represent each segment of a Bezier curve as a Bezier curve with a new set of control points Splitting a Bezier curve into smaller pieces is also useful as a divide and conquer strategy for rendering and intersection algorithms The process of splitting a Bezier curve into two or more Bezier curves that represent the exact same curve is called Bezier subdivision see Figure 1 PoQo P3R3 Figure 1 Bezier subdivision for a cubic Bezier curve The Bezier curve Pt with control points P0P1f i is split into two Bezier curves the left Bezier segment Qt has control points Q0Q1Q2Q3 the right Bezier segment Rt has control points R0R1R2R3 The basic problem in Bezier subdivision is given a collection of control points P0 describe a Bezier curve over the interval 4117 find the control points Q0Qn and R0Rn that describe the segments of the same Bezier curve over the intervals 41 c and ab Remarkably the solution to this problem is provided by the same de Casteljau algorithm that we use to evaluate points on a Bezier curve The de Casteljau Subdivision Algarithm Let Pt be a Bezier curve over the interval 41 b with control points Pquot To subdivide Pt at t c run the de Casteljau evaluation algorithm for Pt at t c The points Q0 Q that emerge along the left lateral edge of the de Casteljau diagram are the Bezier control points for the segment of the curve from t 41 to t c and the points R that emerge along the right lateral edge of the de Casteljau diagram are the Bezier control points for the segment of the curve from t c to t I see Figure 2 Notice that when E 41 b 2 is the midpoint of the parameter interval 41 b then b cb 4112c 41b 41 so the labels along all the edges in the de Casteljau subdivision algorithm evaluate to 12 Thus for midpoint subdivision the de Casteljau subdivision algorithm is independent of the parameter interval see Figure 3 2 Q3 R0 7 7 y 0 Q2 R1 b C KGZF K4 Q1 V R2 C a b V byK abKa Q0 P0 P 1 132 P3 R3 Figure 2 The de Casteljau subdivision algorithm for a cubic Bezier curve with control points RP1 P2 P3 The points Q0 Q1 Q2 Q3 that emerge along the left lateral edge of the triangle are the Bezier control points for the segment of the original curve from t a to tc the points R0 R1 R2 R3 that emerge along the right lateral edge of the triangle are the Bezier control points for the segment of the original curve from t c to t b Q3R0 12 W2 Q2 R1 12 n My 2 Q1 V R2 12 212 m My W2 Q0P0 102 P 1 P3 R3 Figure 3 The de Casteljau subdivision algorithm for a cubic Bezier curve at the midpoint of the parameter interval The labels along all the edges evaluate to 12 so midpoint subdivision does not depend on the choice of the parameter interval We shall defer the proof of the de Casteljau subdivision algorithm till Lecture 26 In this lecture we will study the consequences of this subdivision algorithm Figure 4 provides a geometric interpretation for the de Casteljau subdivision algorithm Pa P0Qo P3R3 Figure 4 Geometric interpretation of the de Casteljau subdivision algorithm for a cubic Bezier curve Pt with control points P0P1 P2P3 The points Q0Q1Q2Q3 are the Bezier control points of the segment of the original curve from t a to t c and the points R0R1R2 R3 are the Bezier control points of the segment of the original curve from t c to t b When we subdivide a Bezier curve the new control polygons appear closer to the Bezier curve than the initial control polygon see Figures 1 and 4 Suppose we continue recursively subdividing each Bezier segment Then in the limit these control polygons converge to a smooth curve see Figure 5 We shall now show that this limit curve is in fact the Bezier curve for the original control polygon For convenience we will restrict our attention to recursive subdivision at the midpoint of the parameter interval though the results are much the same for any value that splits the parameter intervals in a constant ratio Figure 5 Control polygons converge to Bezier curves under recursive subdivision Here the original control polygons left and the first three levels of subdivision right are illustrated Theorem 1 The control polygons generated by recursive subdivision converge to the Bezier curve for the original control polygon Proof Suppose that the maximum distance between any two adjacent control points is d By construction the points on any level of the de Casteljau algorithm evaluated at the midpoint of the parameter domain lie at the midpoints of the edges of the polygons generated by the previous level because the labels along all the edges evaluate to 12 see Figure 3 Therefore it follows easily by 4 induction that adjacent points on any level of the de Casteljau diagram are no further than d units apart see Figure 6 P0Qa P3R3 Figure 6 One level of the de Casteljau algorithm for a cubic Bezier curve evaluated at the midpoint of the parameter domain If adjacent control points 11 1 P2P3 are no further than d units apart then adjacent points Q1 V R2 on the first level of the de Casteljau algorithm can also be no further that d units apart By the same midpoint argument as we proceed up the de Casteljau diagram adjacent points along the left or right lateral edge of the triangle can be no further than d 2 units apart Hence as we apply recursive subdivision the distance between the control points of any single control polygon must converge to zero Since the first and last control points of a Bezier control polygon always lie on the Bezier curve these control polygons must converge to points along the Bezier curve for the We can also subdivide tensor product Bezier patches Recall from Lecture 24 that a Bezier surface Bs t is defined by applying the de Casteljau algorithm in the parameter s to a collection of control points defined by the Bezier curves P0tPmt in the parameter t To subdivide the original control polygon Bezier patch along the parameter line t to simply subdivide each of the curves P0 t Pmt at t t0 Similarly to subdivide the Bezier patch along a parameter line 5 so recall that the same Bezier surface Bs t is defined by applying the de Casteljau algorithm in the parameter t to a collection of control points defined by the Bezier curves PsP s in the parameter 5 Thus to subdivide the Bezier patch along the parameter line 5 so simply subdivide each of the curves Pg HP 5 at s so Now we have the following result 5 Theorem 2 The control polyhedra generated by recursive subdivision converge to the tensor product Bezier patch for the original control polyhedron provided that the subdivision is done in both the s and tdirections The proof of Theorem 2 for Bezier surfaces is much the same as the proof of Theorem 1 for Bezier curves so we shall not repeat the proof here Notice however that we must be careful to subdivide in both the s and the tdirections If we subdivide only along one parameter direction convergence is not assured because in the limit each of the control polyhedra will not necessarily shrink to a single point Thus to guarantee convergence it is best to alternate subdividing in the s and t parameter directions 3 Rendering and Intersection Algorithms Subdivision is our main mathematical tool for analyzing Bezier curves and surfaces Here we shall apply recursive subdivision to develop fast robust algorithms for rendering and intersecting Bezier curves and surfaces 31 Rendering and Intersecting Bezier Curves To render a Bezier curve we could begin by applying the de Casteljau evaluation algorithm to compute lots of points along the curve We could then display a dense collection of points on the curve or we could connect consecutive points on the curve with straight lines and display these line segments But Bezier curves are smooth curves If we applied this approach to rendering Bezier curves how many points would we need to compute in order for the curve to appear smooth Some parts of a Bezier curve may be relatively flat so in these segments we would need to compute only a few points and connect these points with straight lines whereas other parts of a Bezier curve may be highly bent and in these locations we would need to compute quite a lot of points for the line segments approximating the curve to appear smooth see Figure 7 The de Casteljau evaluation algorithm allows us to compute lots of points along a Bezier curve But if we want an accurate portrayal of a Bezier curve it is not clear how many points to compute or where on the curve to concentrate these computations Recursive subdivision solves both of these problems only a small amount of subdivision is required on segments where the curve is relatively at while additional subdivision can be performed on segments where the curve is highly bent The convergence of recursive subdivision is quite fast and the output of recursive subdivision appears smooth see Figure 5 This rapid convergence and smooth appearance leads to the following recursive subdivision algorithm for rendering Bezier curves Figure 7 A cubic Bezier curve that is relatively at near the end points but highly curved towards the center left Thus near the end points we need to compute only a few points and connect these points with straight lines whereas near the center we need to compute quite a lot of points for the line segments approximating the curve to appear smooth right Rendering Algorithm Bezier Curves If the Bezier curve can be approximated to within tolerance by the straight line segment joining its first and last control points then draw either this line segment or the control polygon Otherwise subdivide the Bezier curve at the midpoint of the parameter interval and render the segments recursively To intersect two Bezier curves we could use the rendering algorithm to generate a piecewise linear approximation for each of the two curves and then intersect all these line segments But this approach would be highly inef cient because most of the short line segments would not intersect We can avoid these needless computations by combining recursive subdivision with the convex hull property in order to avoid trying to compute intersections for those parts of the curve that fail to intersect Intersection Algorithm Bezier Curves If the convex hulls of the control points of two Bezier curves fail to intersect then the curves themselves do not intersect Otherwise if each Bezier curve can be approximated by the straight line segment joining its rst and last control points then intersect these line segments Otherwise subdivide the two Bezier curves and intersect the pieces recursively To determine whether a Bezier curve can be approximated to within tolerance by the straight line segment joining its rst and last control points it is suf cient by the convex hull property to test whether all the interior control points lie within tolerance of this line segment But recall from Lecture 11 Section 412 that the distance between a point P and a line L determined by a point Q and a direction vector v is given by 7 2 dist2PLP QI2 M 31 v o v Therefore to test whether the control points Pk k 1n 1 lie within some tolerance 8 of the line determined by the first and last control points P0P we set v P P0 in Equation 31 and test whether or not 2 Pk P0 Pn Po lt 82 2 P 32 IPk 0 PnPOPnPO Be careful It may happen that a control point BC is close to the line L determined by the first and last control points P0P even though the orthogonal projection of BC onto L does not lie inside the line segment P0P that is BC may be close to the line L even though it is not close to the line segment P0P To be sure that BC lies close to the line segment P0P you need only check that in addition to Equation 32 05Pk P039P P0SIP P02 33 It is relatively easy to test whether or not a Bezier curve can be approximated to within some tolerance by a straight line segment On the other hand nding and intersecting the convex hulls of two Bezier curves can be quite dif cult and time consuming In practice the convex hulls in the intersection algorithm are typically replaced by bounding boxes which are much easier to compute and intersect than the actual convex hulls simply take the minimum and maximum 6 and y coordinates of the control points Since the subdivision algorithm converges rapidly not much time is lost by replacing convex hulls with bounding boxes To complete the intersection algorithm for Bezier curves we need to be able to intersect two line segments L1Sl SP0SP1P0SP1 P0 Osssl 2t1 tQ0tQ1Q0tQ1 Q0 Ostsl Two in nite lines intersect when 113 L20 that is when P0SP1 P0Q01Q1 Qo or equivalently when 5P1 P0 Q1 Q0Q0 P0 Dotting both sides first with P1 P0 and then with Q1 Q0 generates two linear equations in two unknowns sltP1 P039P1 PotQ1Qo39P1 Pm Q0 P039P1 P0 34 SP1Po39Q1 QotQ1 Qo39Q1 QoQoPo39Q1 Q0 which are easy to solve for the parameters st see Lecture 11 Section 51 The intersection point lies on the two line segments if and only 0 s s t s 1 In this case we can compute L1 s or 2t to find the actual intersection point 32 Rendering and Intersecting Bezier Surfaces The rendering and intersection algorithms for Bezier curves can be extended to rendering and intersection algorithms for Bezier surfaces Line are replaced by planes line segments are replaced by triangles and recursive subdivision for Bezier curves is replaced by recursive subdivision for Bezier surfaces To render a Bezier patch we must first polygonalize the patch so we begin with an algorithm to approximate a Bezier patch by a collection of triangles Triangulation Algorithm Bezier Surfaces If the Bezier patch can be approximated to within tolerance by two triangles each determined by three of its four corner control points and if the four Bezier boundaries of the Bezier patch can be approximated by straight line segments joining the four corner control points then triangulate the Bezier patch by the two triangles determined by the four corner control points Otherwise subdivide the Bezier surface at the midpoint of the parameter interval ins or t and triangulate the segments recursively Rendering Algorithm Bezier Surfaces Triangulate the Bezier patch Apply your favorite shading and hidden surface algorithms to render the triangulated patch Ray Tracing Algorithm Bezier Surfaces If the ray does not intersect the convex hull of the control points of the Bezier patch then the ray and the patch do not intersect Otherwise if the Bezier patch can be approximated to within tolerance by two triangles each determined by three of its four corner control points and if the four Bezier boundaries of the Bezier patch can be approximated by straight line segments joining the four corner control points then intersect the ray with the two triangles determined by the four comer control points Otherwise subdivide the Bezier patch and ray trace the segments recursively Keep the intersection closest to the eye We already know from Section 31 how to test if a boundary Bezier curve can be approximated by a straight line joining two of the boundary control points We need to perform this test in the triangulation algorithm to be sure that after subdivision cracks do not appear between adjacent triangles If a boundary is not a straight line then subdividing on one side of the boundary 9 but not the other may introduce a tear between adjacent triangles But when the boundaries are at such cracks will not appear To determine whether a Bezier surface can be approximated to within tolerance by a pair of triangles determined by its four corner control points it is sufficient by the convex hull property to test whether each control point lies within some tolerance of at least one of the two triangles Now recall from Lecture 11 Section 413 that the distance between a point P and a plane S determined by a point Q and a normal vectorN is given by P Q 39 N INI 39 Therefore to test whether a control point P17 lies within some tolerance 8 of the plane determined by distPS 35 the three corner control points P00P0 Pm0 we set N P0 P00gtltPm0 P00 in Equation 35 and test whether or not Plj P0039N IN If this test fails we apply the analogous test with the plane determined by the control points P mn lt 3 36 P0 Pm0 Again we must be careful It may happen that a control point P17 lies close to the plane S of a triangle A even though the orthogonal projection of the point P17 onto the plane S does not lie inside the triangle A that is Ply may be close to the plane S even though P17 is not close to the triangle A To be sure that this is not the case you need only check that the orthogonal projection P17 Pij Q 39NN lies inside A Now recall from Lecture 19 Section 3 that a point R lies inside a triangle with vertices P0 P1 P2 if and only if detNI1 PiR Pi20 i012 where N P1 P0 XP2 P0 is the normal to the plane of the triangle These tests should be carried out first with APOOPO quotPmo and only if these tests fail should the tests then be performed with APmnPO Pmo Notice that in the ray tracing algorithm we do not simply triangulate the patch and then ray trace the triangulated approximation Rather we first perform a convex hull test in order to eliminate as many subpatches as possible before we perform intersection calculations Finding the convex hull of a Bezier patch can be quite difficult and time consuming In practice for surfaces as with curves the convex hull is replaced by a bounding box Again since the subdivision algorithm converges rapidly not much time is lost in the ray tracing algorithm by replacing convex hulls with bounding boxes To complete the ray tracing algorithm for Bezier patches we need to be able to intersect a line with a planar polygon Here we can use the algorithm described in Lecture 19 Section 3 Finally a Bezier patch may self shadow that is a light ray may not be able to reach part of a Bezier patch because the light has already struck another part of the patch Therefore at the end of the ray tracing algorithm we discard all the intersections of the ray and the patch except for the intersection closest to the eye 4 The Variation Diminishing Property of Bezier Curves We introduced Bezier curves because unlike polynomial interpolation Bezier approximation does not introduce oscillations not already present in the data This property of Bezier curves is called the variation diminishing property Recall from Lecture 24 that a curve Bt for a control polygon P is said to be variation diminishing if for every line L intersections of Bt and L s intersections of P and L We are now going to use Bezier subdivision to prove the variation diminishing property of Bezier curves One way to introduce variation diminishing schemes is by corner cutting Start with a polygon P and form another polygon Q by cutting a corner off P see Figure 8 Then it is easy to see that every line L intersects P at least as often as L intersects Q Thus Q is variation diminishing with respect to P Pl Q2 Q3P2 Q1 Q4P3 Q0P0 Q0Po Figure 8 Corner cutting The polygon with vertices Q Qi is generated from the polygon with vertices P Pj by cutting off the corner at P1 left Every line L intersects P at least as often as L intersects Q because if L intersects the line segment Q1Q2 then L must intersect either P0P1 or Ple right Now look at the geometric interpretation of the de Casteljau subdivision algorithm in Figure 3 Evidently the de Casteljau subdivision algorithm is a comer cutting procedure first the comers at P1P2 are cut off then the comer at A is cut off see Figure 9 P0Qo P3R3 POQG P3R3 First step Second step Figure 9 The de Casteljau subdivision algorithm as a sequence of comer cuts In the first stage comers are cut off at P1P2 in the second stage the comer is cut off at A Compare to Figure 3 Although we have illustrated only the cubic case in Figure 9 it is easy to verify that the de Casteljau subdivision algorithm is a comer cutting procedure in all degrees This observation leads to the following result Theorem 3 Bezier curves are variation diminishing Proof Since recursive subdivision is a comer cutting procedure the limit curve must be variation diminishing with respect to the original control polygon But by Theorem 1 the Bezier curve is the limit curve generated by recursive subdivision so Bezier curves are variation diminishing By the way there is no known analogue of the variation diminishing property for Bezier surfaces because for Bezier surfaces subdivision is not a comer cutting procedure 5 Joining Bezier Curves Smoothly In Lecture 24 Section 5 we used our procedure for differentiating the de Casteljau algorithm for Bezier curves to derive constraints on the location of the control points to insure that two Bezier curves meet smoothly where they join Given a Bezier curve Pt with control points P0 Pn we derived the following constraints for the location of the control points Q0 Qn of another Bezier curve Q t that meets the first curve and matches the first k derivatives of Pt where they join 12 k0 gt Q0Pn k1 gt Q1PnP P1 51 k2 gt Q2 P2 4P P1 We observed that each derivative generates one new constraint on one additional control point These constraints are easy to solve but rather cumbersome to write down Here we show how to use subdivision to determine the location of the points Q0 Qk that guarantee k fold continuity at the join We know that the location of the points Q0Qk is unique If we could find a curve Qt that meets the original curve Pt smoothly at the join then the control points of Q I would necessarily give the location of the points Q0 Qk But we certainly do know such a curve for Pt meets itself smoothly at the join Suppose that Pt is parameterized over the interval 6117 Let Qt be P I over the interval 17 217 a that is the interval starting at 17 and with the same length as 6117 Then Pt and Qt surely meet smoothly at t 17 All we need now are the Bezier control points of Q I To find the Bezier control points of Pt over the intervals 61 c and 017 we can subdivide the Bezier curve P t at t 0 Nothing in our subdivision algorithm requires that a s c s 17 If we take 0 217 a then the de Casteljau subdivision algorithm will generate the Bezier control points for the curve P I over the intervals 61 217 a and 217 a17 By the symmetry property of Bezier curves see Lecture 24 Exercise 2 the Bezier control points for the interval 217 a17 are the same as the Bezier control points for the interval 17217 a but in reverse order Thus we can read off the control points Q0 Qk from the right lateral edge of the de Casteljau subdivision algorithm for c 217 a But in this algorithm the labels on all the right pointing arrows are 1 because 17 217 a 17 a 1 and the labels on all the left pointing arrows are 2 because 217 a a 17 a 2 Notice that these labels are independent of the interval 61 17 hence this algorithm is independent of the parameter interval We illustrate this algorithm in Figure 10 for cubic Bezier curves yvy glV 79 g 2 m 12 Pl P 3 Q0 Figure 10 The de Casteljau subdivision algorithm at c 2b a for cubic Bezier curves The first k1 points QO Qk that emerge on the right lateral edge of the diagram are the control points that guarantee k fold continuity at the join Compare these points to the values in Equations 51 6 Summary Subdivision is our main technical tool for analyzing Bezier curves and surfaces In this lecture we used Bezier subdivision to i develop a divide and conquer strategy for rendering and intersecting Bezier curves and surfaces ii prove the variation diminishing property for Bezier curves iii guarantee that two Bezier curves connect with k fold smoothness at their join The basic problem in Bezier subdivision is given a collection of control points P0P that describe a Bezier curve over the parameter interval 6117 find the control points Q0Q and R0Rn that describe the segments of the same Bezier curve over the parameter intervals 610 and 017 De Casteljau s evaluation algorithm for Bezier curves is also a subdivision procedure The subdivision control points Q0 Q and R0R emerge along the left and right lateral edges of the de Casteljau evaluation algorithm at t c Bezier subdivision is usually applied at the midpoint of the parameter domain where the labels along all the arrows are 12 see Figure 11 Q3 10 12v Km 92 R1 12v 12 174 2 Q1 V R2 124 V2 12V 121y39 12 Q0Po Ii pi P3R3 Figure 11 The de Casteljau subdivision algorithm for a cubic Bezier curve at the midpoint of the parameter interval Midpoint subdivision is independent of the choice of the parameter domain Exercises 1 Let P t be a Bezier curve de ned over the interval 6L 1 a Show that in the de Casteljau subdivision algorithm at c 1 ra rb the labels on all the right pointing arrows are 1 r and the labels on all the left pointing arrows are r see Figure 12 b Conclude from part a that if we subdivide at a xed ratio of the parameter domain then the de Casteljau subdivision algorithm is independent of the parameter interval Q3 R0 1 739 V Q2 R1 739 1739 N Q1 V R2 1 V 17 17 Q0 P0 Ii 2 P3 R3 Figure 12 The de Casteljau subdivision algorithm at the parameter value c 1 ra rb for a cubic Bezier curve defined over the interval 6L 1 The labels on all the right pointing arrows are 1 r and the labels on all the left pointing arrows are r 2 Consider a Bezier curve defined over the interval 01 Bezier subdivision at t 1 2 generates a binary tree whose nodes are control polygons Denote the original control polygon by P and let this polygon be the root of the tree Let P0 the left child of P denote the control polygon for the left segment of the Bezier curve from t 0 to t 1 2 and let Ii the right child of P denote the control polygon for the right portion of the curve from t 1 2 to t 1 Continue to build this binary tree recursively in this fashion Thus if Pb is a node in the tree then Ii represents the control polygon for a portion of the curve and Pbo the left child of Pb represents the control polygon for the left half of the Bezier segment represented by Pb while Pbl the right child of Pb represents the control polygon for the right half of the Bezier segment represented by Ii see Figure 13 P POR1 HOHIl1 P000 P001 P010 I611 I100 Pror H10 fin Figure 13 The binary tree of control polygons generated by recursive subdivision of a Bezier curve at t 1 2 a Prove that Plumb is the control polygon for the original Bezier curve from t b to t b 2 where b is the binary fraction represented by 0171 b b Prove that the sequence of control polygons Pbl Pble 371an converges to the point on the Bezier curve at parameter value b Limn 00 Obi ml 3 Develop an algorithm to intersect a Bezier curve with a Bezier surface based on recursive subdivision 4 Develop an algorithm to intersect two Bezier patches based on recursive subdivision 16 5 Prove Theorem 2 that the control polyhedra generated by recursive subdivision converge to the tensor product Bezier patch Bst for the original control polyhedron provided that the subdivision is done in both the s and tdirections 6 Let P t be a Bezier curve with control points P0 P a Prove that the arc length of a Bezier curve is greater than or equal to the length of the line joining the first and last control points and less than or equal to the perimeter of the control polygon that is n l an Pols arclengthP t 5 k2 Pk1 Pkl 0 Explain how to use the result of part a to compute the arc length of a Bezier curve to Within any desired tolerance Programming Projects 1 Bezier Curves and Surfaces Implement a modeling system based on Bezier curves and surfaces in your favorite programming language using your favorite API a 0 Q0 Include algorithms for rendering Bezier curves and surfaces based on recursive subdivision Incorporate the ability to move control points interactively and have the Bezier curve or surface adjust in real time Create a new font using Bezier curves Build some interesting freeform shapes using Bezier patches 2 Root Finding Algorithm for Polynomials in Bezier Form A Implement the following root finding algorithm for polynomials of arbitrary degree n Input co c Bezier coefficients of P I over the interval 6L 1 Root Finding Algorithm 1 If 01 0 i0j 1 then a there isamultiple root of order j at t a set 39 1 CkLijk k0n j kjk1b a nn j If cni0i0j 1then a there isamultiple root of order j at tb set 17 n n j 1 k j0k n kn J klb a n n j 3 If ck gt 0 for all k or if ck lt 0 for all k then there is no root in the interval a 17 STOP 4 If ck 2 0 for 0 5k lt i and ck s 0 for is ks 11 one sign change then a there is exactly one root r in the interval 6L 1 b if b a lt8 set rab 2 otherwise subdivide the interval at the midpoint and search for the root in each interval recursively 5 Otherwise subdivide the interval at the midpoint and find the roots in each interval recursively B Prove that this algorithm finds all the roots of the given polynomial in the interval 6L 1 C Compare the speed and accuracy of this root finding algorithm to Newton s method Lecture 23 Radiosity And he shall be as the light of the morning 2 Samuel 234 1 Radiosity Radiosity models the transfer of light between surfaces Recursive ray tracing also models light bouncing off surfaces but ray tracing makes several simplifying assumptions that give scenes a harsh unnatural look Ray tracing assumes that all light sources are point sources and that the ambient light is constant throughout the scene These assumptions lead to stark images with sharp shadows In contrast radiosity models all surfaces as both emitters and reflectors This approach softens the shadows and provides a more realistic model for ambient light Informally radiosity is the rate at which light energy leaves a surface There are two contributions to radiosity emission and reflection Hence radiosity emitted energy re ected energy For the purpose of display we shall identify intensity with radiosity Radiosity computations typically take much longer than recursive ray tracing because the model of light is much more complex To simplify these computations we shall model only diffuse reflections we shall not attempt to model specular reflections with radiosity Since radiosity replaces ambient and diffuse intensity radiosity is view independent Thus we can reuse the same computation for every viewpoint once we compute the radiosity of all the surfaces View dependent calculations are required only to compute hidden surfaces 2 The Radiosity Equations We will begin with a very general integral equation called the Rendering Equation based on energy conservation We will then repeatedly simplify and discretize this equation till we get a large system of linear equations the Radiosity Equations which we can solve numerically for the radiosity of each surface Radiosity is identified with intensity so once we have the radiosity for each surface we can render the scene 21 The Rendering Equation Energy conservation for light is equivalent to Total Illumination Emitted Energy Re ected Energy We can rewrite these innocent looking words as an integral equation called the Rendering Equation Rendering Equation Ixx39 Exx39 f3 pxx39xquot1x39 x39dx 21 where 26 x39 is the total energy passing from x to x Ex x39 is the energy emitted directly from x to x px x39 x39 is the re ection coefficient the percentage of the energy transferred from xquot to x that is passed on to x Essentially all of the computations in Computer Graphics that involve light are summarized in the Rendering Equation Notice in particular that the Rendering Equation is precisely the setup for recursive ray tracing 22 The Radiosity Equation Continuous Form The continuous form of the Radiosity Equation is just the Rendering Equation restricted to diffuse re ections Once again by conservation of energy Radiosity Emitted Energy Re ected Energy Now however since we are dealing only with diffuse re ections we can be more specific about the form of the re ected energy Restricting to diffuse re ections leads to the following integral equation for radiosity Radiosilv Equation F 39 Form cos0cos0 Bx Ex pdxfs By2 Vx y dy 22 n r x where Bx is the radiosity at the point x which we identify with the intensity or energy re ecting off a surface in any direction that is the total power leaving a surfaceunit areasolid angle This energy is uniform in all directions since we are assuming that the scene has only diffuse re ectors Ex is the energy emitted directly from a pointx in any direction This energy is uniform in all directions since we are assuming that the scene has only diffuse emitters pdx is the diffuse re ection coefficient the percentage of energy re ected in all directions from the surface at a point x By definition 0 s pdx s 1 Vx y is the visibility term Vx y 0 ifx is not visible from y Vx y 1 ifx is visible from y 0 2 angle between the surface normal N at x and the light ray L to y 0 2 angle between surface normal N at y and the light ray L to x rx y 2 distance from x to y In the Radiosity Equation the term 0 0 f3 By COSZAVOC y dy 2 energy reaching the pointx from all other points y n r Jay 0 0 pdx fSBy COSZAVOC ydy total energy re ected from x n r x y The factor 1 r2x y models an inverse square law since the intensity of light varies inversely as the square of the distance The factors cos0cos 039 come from Lambert s Law see Lecture 16 Section 4 and represent projections of the flux onto the emitting and reflecting surfaces see Figure 1 and the accompanying discussion The appearance of the factor aquot in the denominator will be explained shortly below To understand the cosine terms better consider two small surface patches Recall that the intensity or radiosity on any facet from any other facet is given by Light Deposited Beam Cross Section receptor source Unit Area Receptor Facet Area where Light Emitted Beam Cross Section Unit Area Source Facet Area I source I emitter 39 But from Figure 1 B C S ti eam ross ec on COS0 COS9 Facet Area receptor 0050 0059 emitter Facet Source Beam Cross Section F dcet Receptor Figure 1 Lambert s Law Intensity is given by the ratio of the beam cross section to the facet area which in turn is equal to the cosine of the angle between the beam and the surface normal Two cosines appear one for the source and one for the receptor Thus Lambert s Law accounts for the two cosines that appear in the Radiosity Equation The factor aquot in the denominator of the second term on the right hand side of Equation 22 arises for the following reason Recall that in the Rendering Equation 3 px39 x x39 the percentage of the energy transferred from x to x that is passed on to a single point x Note that here we have reversed the roles of x and x whereas in the Radiosity Equation pdx the percentage of energy re ected in all directions from the surface at a pointx Thus we need to get from px39 x x in the Rendering Equation to pdx in the Radiosity Equation We shall now show that these two functions differ by a factor of TE Directions can be represented by points on the unit sphere and points on the unit sphere can be parametrized by two angles QB The angle 0 represents the angle between the z axis and the vector from the center of the sphere to the point 0 on the sphere and the angle represents the amount of rotation around the equator from the x axis to the great circle of constant longitude Since pdx is the percentage of energy reflected in all direction whereas px39 xx39 is the percentage of energy re ected in one fixed direction it follows that pdx is the integral of px39 xx39 over the unit hemisphere that is over all the directions that make an acute angle with the normal vector at x which we identify with the z axis A factor of cos0 must appear in this integral for the same reason projection that this factor appears in Lambert s Law Thus pdx prx39xx cos0dS where H is a unit hemisphere centered at 6 Since we are dealing with diffuse re ection the function px39 2626 is the same in all directions Thus we can pull px39 2626 outside the integral so pdx px39 xx39fH cos0dS 23 It remains then to compute chos 0 dS To compute this integral we use the parametrization 0 of the unit sphere provided by spherical coordinates that is by setting S0 sin0cos sin0sin cos6 24 With this parametrization a differential area parallelogram on the unit sphere is given by BS 0 BS 0 BS 0 BS 0 cm mdQX new 4 X 4 SW B 0 B B 0 B But by Equation 24 w cos 0cos cos0 sin sin0 w sin0sin sin0cos 0 so by direct computation BSUM X BS0 5mm 30 M 39 Therefore 2 chos6ds 3 f6 cos0sin0d0d f3 Huge 225 3 n We conclude then from Equation 23 that pdx npx39 xx39 Thus when we replace px39 2626 in the Rendering Equation by pdx in the Radiosity Equation we must divide by TC This accounts for the factor aquot in the denominator of the second term on the right hand side of the Radiosity Equation 23 The Radiosity Equations Discrete Form To find the radiosity at any point we must solve the Radiosity Equation for Bx that is we must calculate the integral on the right hand side of Equation 22 But this integral is not easy to compute Worse yet Bu appears on both sides of the Radiosity Equation thus we must know Bu to find Bu The solution to both problems is to discretize the Radiosity Equation by breaking the surfaces in the scene into small patches Since radiosity is approximately constant over a small patch we shall be able to replace integrals by sums and continuous functions by discrete values The integral equation then reduces to a large system of linear equations which we shall be able to solve by numerical methods To discretize the Radiosity Equation we begin by breaking the surfaces S into small patches P j 1N Over a small patch P the radiosity By is approximately a constant B j and the integral over S breaks up into a sum of integrals over the patches Pj Therefore by Equation 22 0 0 Bltx Ex pdxfSBy SZiVltxydy n r xy N cos 0cos0 2395 x Ex pdx2 ijp2 VxydAJ F1 In x y We still need to discretize Bx on the left hand side and Ex on the right hand side of Equation 25 We can approximate the radiosity and energy of single patch I by an area weighted average Thus Bl 1AifPiBxdAi El 1AifPi ExdAl Integrating Equation 25 over the patch I and dividing by the patch area A yields N r cos0cos 0 Bi Ei pi Bj1Aifpi fpj 2 VxydAdAJ 11 71 r xy Notice that the double integral cos0cos0 Fly 1AifpfP Z VxydAjdAi 26 l n r x y is independent of the radiosity and depends only on the geometry of the facets The parameters Fly are called form factors we shall have a lot more to say about these form factors shortly We have now reduced the Radiosity Equation to the following discrete form Radiosity Equations Discrete F arm N BEp2FJBj i1N 27 j1 where B is the radiosity of patch I which we identify with intensity E is the energy emitted from patch I uniform in all directions since by assumption we are dealing only with diffuse emitters Fly are the form factors which depend only on the geometry of the scene and are independent of the lighting 0 is the diffuse reflection coefficient for patch I 0 s p s 1 Notice in particular that N 2 17ij 2 energy reaching patch I from all the other patches j1 N p 2 Fij 2 energy re ected from the patch j1 The discrete form of the Radiosity Equations given in Equation 27 are the equations that we are going to solve for the radiosities B These linear equations for B are typically the starting point for most discussions of radiosity The energies E and the diffuse reflection coefficients p are usually specified by the user the form factors Fly depend on the geometry of the scene and must be computed Therefore before we can solve the Radiosity Equations we need to compute the form factors

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.