Day 4 Transformation and 2D

Slides:



Advertisements
Similar presentations
Computer Graphics - Transformation -
Advertisements

Today Composing transformations 3D Transformations
1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
Computer Graphics 2D & 3D Transformation.
Transformations Ed Angel Professor Emeritus of Computer Science
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
University of North Carolina at Greensboro
2D Geometric Transformations
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
Chapter 3: Geometric Objects and Transformations Part 2
Transformations. 2 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple geometry, most of us.
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Transformation Jeff Parker, 2011 Based on lectures by Ed Angel.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
10/5/04© University of Wisconsin, CS559 Fall 2004 Last Time Compositing Painterly Rendering Intro to 3D Graphics Homework 3 due Oct 12 in class.
Mathematical Fundamentals
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Transformations
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Geometry: 2-D Transformations Course web page: Chapter #3.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Geometric Objects and Transformation
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
1 User Interaction Includes material by Ed Angel Jeff Parker © 2013.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 13: Hierarchical Modeling and Curves Li Zhang Spring 2010.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Computer Graphics I, Fall 2010 Transformations.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Digital Image Processing CCS331 Camera Model and Imaging Geometry 1.
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
CS5500 Computer Graphics March 6, 2006.
Geometric Transformations
Transformations Objectives
Summary of Properties of 3D Affine Transformations
3D Transformations Source & Courtesy: University of Wisconsin,
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Geometric Transformations
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Geometric Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Transformations Ed Angel
Geometric Objects and Transformations (II)
Transformations Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
Geometric Transformations
Presentation transcript:

Day 4 Transformation and 2D Based on lectures by Ed Angel

Objectives Introduce standard transformations Rotation Translation Scaling Shear Learn to build arbitrary transformation matrices from simple transformations Look at some 2 dimensional examples, with an excursion to 3D We start with a simple example to motivate this

Using transformations void display() { ... setColorBlue(); drawCircle(); setColorRed(); glTranslatef(8,0,0); setColorGreen(); glTranslatef(-3,2,0); glScalef(2,2,2); glFlush(); }

General Transformations Transformation maps points to other points and/or vectors to other vectors v=T(u) Q=T(P)

How many ways? object translation: every point displaced Although we can move a point to a new location in infinite ways, when we move many points there is usually only one way object translation: every point displaced by same vector

Pipeline Implementation frame buffer u T(u) transformation rasterizer v T(v) T(v) T(v) v T(u) u T(u) vertices vertices pixels

Affine Transformations So we want our transformations to be Line Preserving Characteristic of many physically important transformations Rigid body transformations: rotation, translation Scaling, shear Importance in graphics is that we need only transform endpoints of line segments and let implementation draw line segment between the transformed endpoints

Translation Move (translate, displace) a point to a new location Displacement determined by a vector d Three degrees of freedom P’=P+d P’ d P

Define Transformations We wish to take triplets (x, y, z) and map them to new points (x', y', z') While we will want to introduce operations that change scale, we will start with rigid body translations, and we will start in 2-space Translation (x, y)  (x + delta, y) Translation (x, y)  (x + deltaX, y + deltaY) Rotation (x, y)  ? Insight: fix origin, and track (1, 0) and (0, 1) as we rotate through angle a

Not Commutative While often A x B = B x A, transformations are not usually commutative If I take a step left, and then turn left, not the same as Turn left, take a step left This is fundamental, and cannot be patched or fixed.

Rotations Any point (x, y) can be expressed in terms of (1, 0), (0, 1) These unit vectors form a basis The coordinates of the rotation of T(1, 0) = (cos(a), sin(a)) The coordinates of the rotation of T(0, 1) = (-sin(a), cos(a)) The coordinates of T (x, y) = (x cos(a) + y sin(a), -x sin(a) + y cos(a)) Each term of the result is a dot product (x, y) • ( cos(a), sin(a)) = (x cos(a) - y sin(a)) (x, y) • (-sin(a), cos(a)) = (x sin(a) + y cos(a))

Matrices Matrices provide a compact representation for rotations, and many other transformation T (x, y) = (x cos(a) - y sin(a), x sin(a) + y cos(a)) To multiply matrices, multiply the rows of first by the columns of second

Determinant If the length of each column is 1, the matrix preserves the length of vectors (1, 0) and (0, 1) We also will look at the Determinant. 1 for rotations.

3D Matrices Can act on 3 space T (x, y, z) = (x cos(a) + y sin(a), -x sin(a) + y cos(a), z) This is called a "Rotation about the z axis" – z values are unchanged

3D Matrices Can rotate about other axes Can also rotate about other lines through the origin…

Scaling Expand or contract along each axis (fixed point of origin) x’=sxx y’=syx z’=szx p’=Sp S = S(sx, sy, sz) =

Reflection sx = -1 sy = 1 original sx = -1 sy = -1 sx = 1 sy = -1 corresponds to negative scale factors Example below sends (x, y, z)  (-x, y, z) Note that the product of two reflections is a rotation sx = -1 sy = 1 original sx = -1 sy = -1 sx = 1 sy = -1

Limitations We cannot define a translation in 2D space with a 2x2 matrix There are no choices for a, b, c, and d that will move the origin, (0, 0), to some other point, such as (5, 3) in the equation above Further, perspective divide can not be handled by a matrix operation alone We will see ways to get around each of these problems

Image Formation glTranslatef(8,0,0); glTranslatef(-3,2,0); We can describe movement with a matrix Or implicitly glTranslatef(8,0,0); glTranslatef(-3,2,0); glScalef(2,2,2);

Using transformations void display() { ... setColorBlue(); drawCircle(); setColorRed(); glTranslatef(8,0,0); setColorGreen(); glTranslatef(-3,2,0); glScalef(2,2,2); glFlush(); }

Absolute vs Relative move void display() { ... setColorBlue(); glLoadIdentity(); drawCircle(); setColorRed(); glLoadIdentity(); /* Not really needed... */ glTranslatef(8,0,0); setColorGreen(); glLoadIdentity(); /* Return to known position */ glTranslatef(5,2,0); glScalef(2,2,2); glFlush(); }

Order of Transformations Note that matrix on the right is the first applied to the point p Mathematically, the following are equivalent p’ = ABCp = A(B(Cp)) Note many references use column matrices to represent points. In terms of row matrices p’T = pTCTBTAT

Rotation About a Fixed Point other than the Origin Move fixed point to origin Rotate Move fixed point back M = T(pf) R(q) T(-pf)

Instancing In modeling, we often start with a simple object centered at the origin, oriented with the axis, and at a standard size We apply an instance transformation to its vertices to Scale Orient (rotate) Locate (translate)

Example void display() { ... setColorGreen(); glLoadIdentity(); glTranslatef(5,2,0); glRotatef(45.0, 0.0, 0.0, 1.0); /* z axis */ glScalef(2,4,0); drawCircle(); }

Example setColorGreen(); glLoadIdentity(); glRotatef(45.0, 0.0, 0.0, 1.0); /* z axis */ glTranslatef(5,2,0); glScalef(2,4,0); drawCircle(); setColorGreen(); glLoadIdentity(); glTranslatef(5,2,0); glRotatef(45.0, 0.0, 0.0, 1.0); glScalef(2,4,0); drawCircle(); setColorGreen(); glLoadIdentity(); glTranslatef(5,2,0); glScalef(2,4,0); glRotatef(45.0, 0.0, 0.0, 1.0); drawCircle();

Shear Helpful to add one more basic transformation Equivalent to pulling faces in opposite directions

Shear Matrix H(q) = x’ = x + y cot q y’ = y z’ = z Consider simple shear along x axis x’ = x + y cot q y’ = y z’ = z H(q) =

Example Be sure to play with Nate Robin's Transformation example

Matrix Stack It is useful to be able to save the current transformation We can push the current state on a stack, and then Make new scale, translations, rotations Then pop the stack and return to status quo ante

Example

Example Image is made up of subimages

Tree Jon Squire's fractalgl – on examples page This is harder to do from scratch

Rings void display() { int angle; glClear(GL_COLOR_BUFFER_BIT); for (angle = 0; angle < 360; angle = angle + STEP) glPushMatrix(); /* Remember current state */ glRotated(angle, 0, 0, 1); glTranslatef(0.0, 0.75, 0.0); glScalef(0.15, 0.15, 0.15); drawRing(); glPopMatrix(); /* Restore orignal state */ } glFlush();

Rings void display() { int angle; // glClear(GL_COLOR_BUFFER_BIT); for (angle = 0; angle < 360; angle = angle + STEP) glPushMatrix(); /* Remember current state */ glRotated(angle, 0, 0, 1); glTranslatef(0.0, 0.75, 0.0); glScalef(0.15, 0.15, 0.15); drawRing(); glPopMatrix(); /* Restore orignal state */ } glFlush();

drawRing void drawRing() { int angle; for (angle = 0; angle < 360; angle = angle + STEP) glPushMatrix(); /* Remember current state */ glRotated(angle, 0, 0, 1); glTranslatef(0.0, 0.75, 0.0); glScalef(0.2, 0.2, 0.2); glColor3f((float)angle/360, 0, 1.0-((float)angle/360)); drawTriangle(); glPopMatrix(); /* Restore orignal state */ } glFlush();

Fractals - Snowflake curve The Koch Snowflake was discovered by Helge von Koch in 1904. Start with a triangle inscribed in the unit circle To build the level n snowflake, we replace each edge in the level n-1 snowflake with the following pattern The perimeter of each version is 4/3 as long Infinite perimeter, but snowflake lies within unit circle, so has finite area We will use Turtle Geometry to draw the snowflake curve Also what Jon Squire used for Fractal Tree

Recursive Step void toEdge(int size, int num) { if (1 >= num) turtleDrawLine(size); else { toEdge(size/3, num-1); turtleTurn(300); turtleTurn(120); }

Turtle Library /** Draw a line of length size */ void turtleDrawLine(GLint size) glVertex2f(xPos, yPos); turtleMove(size); } int turtleTurn(int alpha) { theta = theta + alpha; theta = turtleScale(theta); return theta; /** Move the turtle. Called to move and by DrawLine */ void turtleMove(GLint size) { xPos = xPos + size * cos(DEGREES_TO_RADIANS * theta); yPos = yPos + size * sin(DEGREES_TO_RADIANS * theta);

Dragon Curve The Dragon Curve is due to Heighway One way to generate the curve is to start with a folded piece of paper We can describe a curve as a set of turtle directions The second stage is simply Take one step, turn Right, and take one step The next stage is Take one step, turn Right, take one step Turn Right Perform the original steps backwards, or Take one step, turn Left, take one step Since the step between turns is implicit, we can write this as RRL …

Dragon Curve The Dragon Curve is due to Heighway One way to generate the curve is to start with a folded piece of paper We can describe a curve as a set of turtle directions The second stage is simply Take one step, turn Right, and take one step The next stage is Take one step, turn Right, take one step Turn Right Perform the original steps backwards, or Take one step, turn Left, take one step Since the step between turns is implicit, we can write this as RRL RRL R RLL

How can we program this? R R L R R L L We could use a large array representing the turns RRL R RLL To generate the next level, append an R and walk back to the head, changing L’s to R’s and R’s to L’s and appending the result to end of array But there is another way. Start with a line At every stage, we replace the line with a right angle We have to remember which side of the line to decorate (use variable “direction”) One feature of this scheme is that the “head” and “tail” are fixed R R L R R L L

Dragon Curve void dragon(int size, int level, int direction, int alpha) { /* Add on left or right? */ int degree = direction * 45; turtleSet(alpha); if (1 == level) { turtleDrawLine(size); return; } size = size/scale; /* scale == sqrt(2.0) */ dragon(size, level - 1, 1, alpha + degree); dragon(size, level - 1, -1, alpha - degree);

Dragon Curve When we divide an int (size) by a real (sqrt(2.0)) there is roundoff error, and the dragon slowly shrinks The on-line version of this program precomputes sizes per level and passes them through, as below int sizes[] = {0, 256, 181, 128, 90, 64, 49, 32, 23, 16, 11, 8, 6, 4, 3, 2, 2, 1, 0}; ... dragon(sizes[level], level, 1, 0); void dragon(int size, int level, int direction, int alpha) { /* size = size/scale; */ dragon(size, level - 1, 1, alpha + degree); dragon(size, level - 1, -1, alpha - degree); }

From last class Alex Chou's Pac Man

Sample Projects From last class

Summary We have played with transformations Spend today looking at movement in 2D Next week, we are onto the Third Dimension! In OpenGL, transformations are defined by matrix operations In new version, glTranslate, glRotate, and glScale are deprecated We have seen some 2D matrices for rotation and scaling You cannot define a 2x2 matrix that performs translation A puzzle to solve The most recently applied transformation works first You can push the current matrix state and restore later Turtle Graphics provides an alternative