Matheatics in Coputer Graphics and Gaes Prof Eanuel Agu Coputer Science Dept. Worcester Polytechnic Institute (WPI)
About Me Professor in WPI Coputer Science Dept Grad school at Uass Aherst (MS, PhD) Research in Coputer graphics for years Teaching coputer graphics for 4 years
What is Coputer Graphics (CG)? Coputer graphics: algoriths, atheatics, progras.. that coputer uses to generate PRETTY PICTURES E.g Techniques to draw a line, polygon, cube Coputer-Generated! Not a picture!
Uses of Coputer Graphics Entertainent: gaes Courtesy: Super Mario Galaxy Courtesy: Final Fantasy XIV
Uses of Coputer Graphics ovies, TV (special effects, aniated characters) Courtesy: Shrek Courtesy: Spideran Note: Gaes and Movie industries Are two biggest hirers of coputer Graphics professionals!!
Uses of Coputer Graphics Displaying Matheatical Functions E.g., Matheatica
Main Career Paths in Coputer Graphics. Artist: Designs characters No ath skills required!!. Prograer: Writes progras to Make characters ove, talk, etc Lots of ath, prograing skills required!! Your students probably Follow prograer path
Soe High School Math Used in CG Geoetry Linear algebra: Matrices, vectors Trigonoetry Coplex nubers Boolean logic Probability
Fractals Matheatical expressions to generate pretty pictures Evaluate ath functions to create drawings Evaluated function approached infinity -> converge to iage i.e f(), f(), f(3).. F( ) Fractal iage exhibits self-siilarity: See siilar sub-iages within iage as we zoo in
Sierpinski Gasket: Popular Fractal (x3, y3) Start with initial triangle with corners (x, y) (x, y). Pick initial point p = (x, y) at rando inside triangle. Randoly select of 3 vertices 3. Find q, halfway between p and randoly selected vertex 4. Draw dot at q 5. Replace p with q 6. Return to step
Exaple: Fractal Terrain Terrain designed with only fractals
Exaple: Fractal Art Courtesy: Internet Fractal Art Contest
Exaple: Mandelbrot Set
Mandelbrot Set Function of interest: Pick constants s and c Orbit: sequence of values (i.e d, d, d 3, d 4, etc): Question: does the orbit converge to a value? c s z f ) ( ) ( c c c c s d c c c s d c c s d c s d 4 3 ) ) ) ) (((( ) ) ) ((( ) ) (( ) (
Mandelbrot Set Exaples orbits: s =, c = -, orbit =,-,,-,,-,,-,..finite s =, c =, orbit =,,,5,6,677 explodes Orbit depends on s and c Basic question: For given s and c, does function stay finite? (within Mandelbrot set) explode to infinity? (outside Mandelbrot set) Definition: if d <, orbit is finite else inifinite
Mandelbrot Set Mandelbrot set: use coplex nubers for c and s Set s =, c as a coplex nuber E.g: s =, c =. +.5i Definition: Mandelbrot set includes all finite orbit c Mandelbrot set progra: Choose s and c, progra calculates d, d, d 3, d 4 and tests if they are finite Choose colors Values of c in andelbrot set
Other Fractal Exaples Gingerbread Man The Fern
Geoetric Representations: 3D Shapes Generated using closed for geoetric equations Exaple: Sphere Sphere Cone Torus Proble: A bit restrictive to design real world scenes ade of spheres, cones, etc
Geoetric Representations: Meshes Collection of polygons, or faces, that for skin of object More flexible, represents coplex surfaces better Mesh? List of (x,y,z) points + connectivity Digitize real objects: very fine esh Each face of esh is a polygon Digitized esh of statue of Lucy: 8 illion faces
Affine Transforations Translation Scaling Rotation Shear Rotate object Translate object Scale object
Affine Transfors: General Approach We can transfor (translation, scaling, rotation, shearing, etc) object by applying atrix ultiplications to object vertices Transfored Vertex Px ' Py ' P ' z 3 3 3 3 33 Transfor Matrix 4 4 34 Px Py P z Original Vertex Note: point (x,y,z) needs to be represented as (x,y,z,), also called Hoogeneous coordinates
3D Translation using Matrices Move each object vertex by sae distance d = (d x, d y, d z ) Exaple: If we translate a point (,,) by displaceent (,4,6), new location of point is (4,6,8) Translate object 8 6 4 6 4 Translation Matrix Original point Translated point Translate x: + = 4 Translate y: + 4 = 6 Translate z: + 6 = 4 ' ' ' z y x z y x d d d z y x * General for
Scaling Transfor Expand or contract along each axis (fixed point of origin) Exaple: If we scale a point (,4,6) by scaling factor (.5,.5,.5) Scaled point position = (,, 3) 6 4.5.5.5 3 Scale Matrix for Scale(.5,.5,.5) Scaled x: x.5 = Scaled y: 4 x.5 = Scaled z: 6 x.5 = 3 ' ' ' z y x S S S z y x z y x General For
Why Matrices? Sequence of transfor atrices can be pre-ultiplied One final resulting atrix applied (efficient!) E.g. transfor x transfor. Q Q Q x y z 3 3 3 3 33 4 4 34 3 3 3 3 33 4 4 34 Px Py Pz Transfored Point Transfor Matrices can Be pre-ultiplied Original Point Coputer graphics card has fast 4x4 atrix ultiplier!!!
Why do we need Shading? Sphere without lighting & shading: Sphere with shading: Has visual cues for huans (shape, light position, viewer position, surface orientation, aterial properties, etc)
What Causes Shading? Shading caused by different angles with light, caera at different points
Calculating Shade Based on Labert s Law: D = I x k D cos (q) Calculate shade based on angle q q Receive ore light Receive less light Represent light direction, surface orientation as vectors Calculate q? Angle between vectors
Shading: Diffuse Light Exaple Different parts of each object receives different aounts of light
References Angel and Shreiner, Interactive Coputer Graphics (6 th edition), Chapter Hill and Kelley, Coputer Graphics using OpenGL (3 rd edition), Chapter