2D Transformation of Graphics

Slides:



Advertisements
Similar presentations
Computer Graphics: 2D Transformations
Advertisements

3D Transformations Assist. Prof. Dr. Ahmet Sayar
Computer Graphics: 3D Transformations
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Geometric Transformations
Three Dimensional Modeling Transformations
1 Computer Graphics Chapter 6 2D Transformations.
Chapter 5 Geometric Transformations
Two-Dimensional Geometric Transformations
2D TRANSFORMATIONS. 2D Transformations What is transformations? –The geometrical changes of an object from a current state to modified state. Why the.
2D TRANSFORMATIONS.
CMPE 466 COMPUTER GRAPHICS
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
CMPE 466 COMPUTER GRAPHICS
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
Computer Graphics with OpenGL 3e
Geometric Transformation-2D
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
CS 450: Computer Graphics 2D TRANSFORMATIONS
UNIT - 5 3D transformation and viewing. 3D Point  We will consider points as column vectors. Thus, a typical point with coordinates (x, y, z) is represented.
Mathematical Fundamentals
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
5.2 Three-Dimensional Geometric and Modeling Transformations 2D3D Consideration for the z coordinate.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University cgvr.korea.ac.kr 2D Geometric Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Lecture Notes: Computer Graphics.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
2D Geometric Transformations
Transformations Jehee Lee Seoul National University.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
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
Introduction to Computer Graphics Geometric Transformations
Computer Graphics 3D Transformations. Translation.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Geometric Transformations
GEOMETRIC TRANFORMATIONS Presented By -Lakshmi Sahithi.
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
3-D Geometric Transformations
Lecture 5: Introduction to 3D
Affine Geometry.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
III- 1 III 3D Transformation Homogeneous Coordinates The three dimensional point (x, y, z) is represented by the homogeneous coordinate (x, y, z, 1) In.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. Why the transformations is needed?
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Computer Graphic 2 D Transformation.
CSCE 441 Computer Graphics: 2D Transformations
Modeling Transformation
Instructor: Dr. Shereen Aly Taie Basic Two-Dimensional Geometric Transformation 5.2 Matrix Representations and Homogeneous Coordinates 5.3 Inverse.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Geometric Transformations
2D Geometric Transformations
Computer Graphics CC416 Week 15 3D Graphics.
Computer Graphics 3D Transformations
Line and Character Attributes 2-D Transformation
TWO DIMENSIONAL TRANSFORMATION
Presentation transcript:

2D Transformation of Graphics Unit 2 2D Transformation of Graphics

What is geometric transformation? Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations.

So the geometric-transformation functions that are available in some system are following: Translation Rotation Scaling Other useful transforms includes: reflection and shear.

Translation Rotation

Scaling Uniform Scaling Un-uniform Scaling

Reflection Shear

Why do we need geometric transformations in CG( motivation )? As a viewing aid As a modeling tool As an image manipulation tool

Two-Dimensional(2D) Translation We perform a translation on a single coordinate point by adding offsets to its coordinates so as to generate a new coordinate position. Similarly, a translation is applied to an object that is defined with multiple coordinate positions by relocating all the coordinate positions by the same displacement along parallel paths. Suppose tx and ty is the translation distances, (x, y) is the original coordinates, is the new coordinate position.

Express the translation use matrix equation as following: Translation is a rigid-body transformation that moves objects without deformation. Ex: Translate a polygon with coordinates A(2, 5), B(7, 10), C(10, 2) by 3 units x direction and 4 units in y direction (Hint : Add 3 to all x values and 4 to all values).

Write a C++ program to translate : A point A line A Rectangle A Polygon (Triangle)

/* C++ program */ #include<iostream.h> #include<graphics.h> #include<math.h> void main() { clrscr(); int x,y,tx,tx; /* initialise graphics ------------------------ */ detectgraph(&gd,&gm); initgraph(&gd,&gm,“c:\\tc\\bgi");

cout<<“Enter x, y:” cin>>x>>y; cout<<“Enter tx,ty” cin>>tx>>ty; putpixel(x,y,15); delay(100); putpixel(x+tx,y+ty,15); getch(); closegraph();}

Translate a line: line(x1,y1,x2,y2); line(x1+tx,y1+ty,x2+tx,y2+ty);

Translate a rectangle: rectangle(x1,y1,x2,y2); rectangle(x1+tx,y1+ty,x2+tx,y2+ty);

Two-Dimensional Rotation We generate a rotation transformation of an object by specifying a rotation axis and a rotation angle. All points of the object are then transformed to new positions by rotating the points through the specified angle about the rotation axis. A 2D rotation of an object is obtained by repositioning the object along a circular path in the xy plane, the rotation axis is perpendicular to the xy plane. Parameters for 2D rotation is rotation angle and a rotation point( pivot point) . Rotation angle define a positive values for counterclockwise rotation about the pivot point.

Substitute expression (1) into (2) r is the constant distance of the point form the origin, angle is the original angular position of the point from the horizontal, and is the rotation angle. Substitute expression (1) into (2) (1) (2)

(3) Matrix form P’=P.R

Example 1 A point (4, 3) is rotated by an angle of 45 degrees. Find the rotation matrix and resultant point. Rotate a line from A(0,0) to B(200,100) by 45 degrees. Rotate a polygon with coordinates A(2, 5), B(7, 10), C(10, 2) by an angle of 45 degrees.

Write a C program to Rotate : A point A line A Rectangle A Polygon (Triangle)

Two-Dimensional(2D) Scaling To alter the size of an object, we apply a scaling transformation. A simple two-dimensional scaling operation is performed by multiplying object positions (x, y) by scaling factors sx and sy to produce the transformed coordinate . Scaling factors sx scales an object in the x coordinate.

Properties of the scaling transformation. Any positive values can be assigned to the scaling factors sx and sy. Values less then 1 reduce the size of object, the object will close up the original at the same time. In contrast , enlarge the size of object. When sx and sy are assigned to the same values, a uniform scaling is produced which maintains relative object proportions.

Unequal values for sx and sy result in a differential scaling that is often used in design applications. Negative values can also be specified for the scaling parameters, this not only resizes an object, it reflects the object one or more of the coordinate axes.

Write a C++ program to scale : A point A line A Rectangle A Polygon (Triangle)

Point: cout<<“Enter x, y:” cin>>x>>y; cout<<“Enter sx,sy” cin>>sx>>sy; Initgraph(&gd,&gm,”..\\bgi”); putpixel(x,y,15); delay(100); putpixel(x*sx,y*sy,15); getch(); closegraph();}

Scale a line: line(x1,y1,x2,y2); line(x1*sx,y1*sy,x2*sx,y2*sy);

Scale a rectangle: rectangle(x1,y1,x2,y2); rectangle(x1*sx,y1*sy,x2*sx,y2*sy);

Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by two units in x-direction and two units in y-direction and plot the graph. Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by -2 units in x-direction and 3 units in y-direction and plot the graph.

Matrix Representations and Homogeneous Coordinates It is well known that many application involves sequences of geometric transformations. For example, an animation might require an object to be translated, rotated and scaled at each increment of the motion. If you want to first rotates an object, then scales it, you can combine those two transformation to a composite transformation like the following equation:

However, it will be difficult to deal with the above composite transformation and translation together. Because, translation is not 2 by 2 matrix representation. So ,here we consider how the matrix representations discussed in the previous sections can be reformulated so that such transformation sequences can be efficiently processed.

In fact, we can expressed three basic two-dimensional transformation( translation, rotation, and scaling) in the general matrix form: Now this equation can be reformulated to eliminate the matrix addition operation using Homogeneous Coordinates.

What is Homogeneous Coordinates? A standard technique for expanding each two-dimensional coordinate position representation (x, y) to three-element representation , called Homogeneous Coordinates, where homogeneous h is a nonzero value such that For geometric transformation, we can chose the homogeneous parameter h to be any nonzero value. Thus there are an infinite number of equivalent homogeneous representations for each coordinate point (x, y) .

A convenient choice is simply to set h=1, so each two-dimensional position is then represented with homogeneous coordinate (x,y,1). Expressing positions in homogenous coordinates allows us to represent all geometric transformation equations as matrix multiplications, which is the standard method used in graphics systems. Two dimensional coordinate positions are represented with three-elements column vectors, and two-dimensional transformation operations are expressed as 3X3 matrices.

Homogeneous coordinate representation of 2D Translation This translation operation can be written in the abbreviated form

Homogeneous coordinate representation of 2D Rotation This translation operation can be written in the abbreviated form

Homogeneous coordinate representation of 2D Scaling This scaling operation can be written in the abbreviated form

Two-Dimensional Composite Transformation Using matrix representations, we can set up a sequence of transformation as a composite transformation matrix, by calculating the product of the individual transformations. And, since many positions in a scene are typically transformed by the same sequence, its is more efficient to first multiply the transformation matrices to form a single composite matrix. So the coordinate position is transformed using the composite matrix M, rather than applying the individual transformations M1 and then M2

General Two-Dimensional Pivot-Point Rotation (Rotation about an arbitrary point) So we can generate a 2D rotation about any other pivot point (x, y) by performing the following sequence of translate-rotate-translate operations. (xr,yr)

(1) Translate the object so that the pivot-point position is moved to the coordinate origin. (2) Rotate the object about the coordinate origin. (3) Translate the object so that the pivot point is returned to its original position. The composite transformation matrix for this sequence is obtained with the concatenation:

Problems: Perform the rotation of a point A(2,3) about point (1,1) by angle of 45 degrees. Perform the rotation of a point A(2,3), B(5,5), C(4,3) about point (1,1) by angle of 45 degrees.

Other 2D transformations: Reflection with respect to the axis X axis • y axis y 1 y 1 1’ 2 3 2 3 3’ 2’ x x 2’ 3’ 1’

Reflection with respect to a line y=x

Shear Two common shearing transformations are those that shift coordinate x values and those that shift y values. An x-direction shear relative to the x axis is produced with the transformation matrix x’ = x + shx · y, y’ = y x y x y (1,1) (0,1) (2,1) (3,1) (0,0) (1,0) (0,0) (1,0)

Y-Shear x’ = x , y’ = y + shy*x

Thank You!!

General 3D Rotations (1) Rotating about an axis that is parallel to one of the coordinates axes. Step1, Translate the object so that the rotation axis coincides with the parallel coordinate axis. Step2, Perform the specified rotation about that axis. Step3, Translate the object so that rotation axis is moved back to its original.

A coordinate position P is transformed with the sequence

(2) Rotated about an axis that is not parallel to one of the coordinate axes. In this case, we also need rotation to align the rotation axis with a selected coordinate axis and then to bring the rotation axis back to its original orientation. A rotation axis can be defined with two coordinate position, or one position and direction angles (direction cosines ). Now we assume that the rotation axis is defined by two points, and that the direction of rotation is to be counter clockwise when looking along the axis from p2 to p1.

The components of the rotation axis vector are then computed as: And the unit rotation-axis vector u is Where

Step1. Translate the object so that the rotation axis passes through the coordinate origin Step2, Rotate the object so that the axis of rotation coincides with one of the coordinate axes. Step3, Perform the specified rotation about the selected coordinate axis Step4, Apply inverse rotations to bring the rotation axis back to its original orientation. Step5 ,Apply the inverse translation to bring the rotation axis to its original spatial position. we can transform the rotation axis onto any one of the three coordinate axes. But the z axis is often a convenient choice.

The first step in the rotation sequence is to set up the translation matrix that repositions the rotation axis so that it passes through the coordinate origin. We move p1 to the origin.

The next step we will put the rotation axis onto the z axis The next step we will put the rotation axis onto the z axis. We can use the coordinate-axis rotations to accomplish this alignment in two steps. For this example, we first rotate about the x axis, then rotate about y axis. The x axis rotation gets vector u into the x-z plane, and the y-axis rotation swings u around to the z axis. y u x z

Since rotation calculations involve sine and cosine functions, so we can use standard vector operation to obtain elements of the two rotation matrices. A vector dot product can be used to determine the cosine term, and a vector cross product can be used to calculate the sine term. Firstly, we establish the transformation matrix for rotation around the x axis by determining the values for the sine and cosine of the rotation angle necessary to get u into the x-z plane.

Inverse Transformation To undo the applied transformation Inverse Transformation is applied. Inverse of T is T-1. T T-1=I (Identity Matrix)

Thank you !!!

Not required

How to rotate a line segment or a polygon? Question 1: If the rotation point is an arbitrary pivot position , can you give the correct rotation expression? How to rotate a line segment or a polygon? (3)

Similarly, we can obtain the matrix representation of General 2D Fixed-Point Scaling.( question ). (1) Translate the object to so that the fixed point coincides with the coordinate origin. (2) Scale the object with respect to the coordinate origin. (3) Use the inverse of the translation in step (1) to return the object to its original position.

(xr,yr) Translate Scale Translate

We also obtain General 2D Scaling Directions. Suppose we want to apply scaling factors with values specified by parameters s1 and s2 in the directions shown in the following fig.

To accomplish the scaling without changing the orientation of the object. (1) we perform a rotation so that the directions for s1 and s2 coincide with the x and y axes, respectively. (2) Then the scaling transformation S(s1,s2) is applied. (3) An opposite rotation to return points to their original orientations.

For example, we turn a unit square into a parallelogram by stretching it along the diagonal from (0,0) to (1,1). x y (0,0) (1,0) (0,1) (1,1) x y (0,0) (3/2,1/2) (1/2,3/2) (2,2) Scale

We first rotate the diagonal onto the y axis using angle 45 degree We first rotate the diagonal onto the y axis using angle 45 degree. Then we double its length with the scaling values s1=1 and s2=2, and then we rotate again to return the diagonal to its original orientation.

Matrix Concatenation Properties (1) Multiplication of matrices is associative. (2) Transformation products, on the other hand, may not be commutative.

Other 2D transformations: Reflection with respect to the axis X axis • y axis • original point y 1 y y 1 1’ 1’ 2 3 2 3 3’ 2 3’ 2 x x x 3 2’ 3’ 1 2 1’

Reflection with respect to a line x y

Shear Two common shearing transformations are those that shift coordinate x values and those that shift y values. An x-direction shear relative to the x axis is produced with the transformation matrix x’ = x + shx · y, y’ = y x y x y (1,1) (0,1) (2,1) (3,1) (0,0) (1,0) (0,0) (1,0)

Now, coordinate positions are transformed as Any real number can be assigned to the shear parameter shx. A coordinate position (x, y) is then shifted horizontally by an amount proportional to its perpendicular distance ( y value ) from the x axis. We can generate x-direction shears relative to other reference lines with yref=-1. Now, coordinate positions are transformed as x’ = x + shx · (y-yref), y’ = y (3,1)

The following Fig. illustrates the conversion of a square into a parallelogram with shy=0.5 and yref=-1. x y x y (2,1) (1,1) (1,1) (0,1) (1/2,0) (3/2,0) (0,0) (1,0) (0,-1)

Shearing operations can be expressed as a sequences of basic transformations. Such as a series of rotation and scaling matrices

General 3D Rotations (1) Rotating about an axis that is parallel to one of the coordinates axes. Step1, Translate the object so that the rotation axis coincides with the parallel coordinate axis. Step2, Perform the specified rotation about that axis. Step3, Translate the object so that rotation axis is moved back to its original.

A coordinate position P is transformed with the sequence

(2) Rotated about an axis that is not parallel to one of the coordinate axes. In this case, we also need rotation to align the rotation axis with a selected coordinate axis and then to bring the rotation axis back to its original orientation. A rotation axis can be defined with two coordinate position, or one position and direction angles (direction cosines ). Now we assume that the rotation axis is defined by two points, and that the direction of rotation is to be counter clockwise when looking along the axis from p2 to p1.

The components of the rotation axis vector are then computed as: And the unit rotation-axis vector u is Where

Step1. Translate the object so that the rotation axis passes through the coordinate origin Step2, Rotate the object so that the axis of rotation coincides with one of the coordinate axes. Step3, Perform the specified rotation about the selected coordinate axis Step4, Apply inverse rotations to bring the rotation axis back to its original orientation. Step5 ,Apply the inverse translation to bring the rotation axis to its original spatial position. we can transform the rotation axis onto any one of the three coordinate axes. But the z axis is often a convenient choice.

The first step in the rotation sequence is to set up the translation matrix that repositions the rotation axis so that it passes through the coordinate origin. We move p1 to the origin.

The next step we will put the rotation axis onto the z axis The next step we will put the rotation axis onto the z axis. We can use the coordinate-axis rotations to accomplish this alignment in two steps. For this example, we first rotate about the x axis, then rotate about y axis. The x axis rotation gets vector u into the x-z plane, and the y-axis rotation swings u around to the z axis. y u x z

Since rotation calculations involve sine and cosine functions, so we can use standard vector operation to obtain elements of the two rotation matrices. A vector dot product can be used to determine the cosine term, and a vector cross product can be used to calculate the sine term. Firstly, we establish the transformation matrix for rotation around the x axis by determining the values for the sine and cosine of the rotation angle necessary to get u into the x-z plane.

We need the angle between vector u and x-z plane . We directly calculate cosine and sine values of . If we represent the projection of u in the zoy plane as the vector Then the cosine of the rotation angle can be determined from the dot product of and then unit vector along the z axis. a z x y b

Similarly, we can determine the sine of from the cross product of So

So the matrix elements for rotation of this vector about the x axis and into the xz plane:

The rotation matrix about y axis is

The third step we have aligned the rotation axis with the positive z axis. The specified rotation angle we can now be applied as a rotation about the z axis z x y

So the transformation matrix for rotation about an arbitrary axis can then be expressed as the composition of these seven individual transformations: