Title: Computer Graphics
1Computer Graphics
- Chapter 5
- Geometric Transformations
Andreas Savva
22D Translation
- Repositioning an object along a straight line
path from one co-ordinate location to another - (x,y) (x,y)
- To translate a 2D position, we add
translation distances tx and ty to the original
coordinates (x,y) to obtain the new coordinate
position (x,y) - x x tx , y y ty
Matrix form
32D Translation
- Moving a polygon from position (a) to position
(b) with the translation vector (-5, 10), i.e.
(a)
(b)
4Translating a Polygon
- class Point2D
- public
- GLfloat x, y
-
- void translatePoly(Point2D P, GLint n,
- GLfloat tx, GLfloat ty)
-
- GLint i
- for (i0 iltn i)
- Pi.x Pi.x tx
- Pi.y Pi.y ty
-
- glBegin (GL_POLYGON)
- for (i0 iltn i)
- glVertex2f(Pi.x, Pi.y)
- glEnd()
52D Rotation
- Repositioning an object along a circular path in
the xy-plane
The original coordinates are
62D Rotation
Matrix form
72D Rotation about a Pivot position
- Rotating about pivot position (xr, yr)
8Translating a Polygon
- class Point2D
- public
- GLfloat x, y
-
- void rotatePoly(Point2D P, GLint n,
- Point2D pivot, GLdouble theta)
-
- Point2D V
- V new Point2Dn
- GLint i
- for (i0 iltn i)
- Vi.x pivot.x (Pi.x pivot.x)
cos(theta) - - (Pi.y pivot.y)
sin(theta) - Vi.y pivot.y (Pi.x pivot.x)
sin(theta) - - (Pi.y pivot.y)
cos(theta) -
- glBegin (GL_POLYGON)
- for (i0 iltn i
- glVertex2f(Vi.x, Vi.y)
92D Scaling
- Altering the size of an object. Sx and Sy are the
scaling factors. If Sx Sy then uniform scaling.
Matrix form
102D Scaling relative to Fixed point
- Scaling relative to fixed point (xf, yf)
OR
where the additive terms xf(1-Sx) and yf(1-Sy)
are constants for all points in the object.
11Translating a Polygon
- class Point2D
- public
- GLfloat x, y
-
- void scalePoly(Point2D P, GLint n, Point2D
fixedPt, - GLfloat Sx, GLfloat Sy)
-
- Point2D V
- V new Point2Dn
- GLfloat addx fixedPt.x (1 Sx)
- GLfloat addy fixedPt.y (1 Sy)
- GLint i
- for (i0 iltn i)
- Vi.x Pi.x Sx addx
- Vi.y Pi.y Sy addy
-
- glBegin (GL_POLYGON)
- for (i0 iltn i
- glVertex2f(Vi.x, Vi.y)
12Matrix Representation
- Use 33 matrices to combine transformations
- Translation
- Rotation
- Scaling
13Inverse Transformations
- Translation
- Rotation
- Scaling
14Example
- Consider the line with endpoints (10, 10) and
(30, 25). Translate it by tx -20, ty -10 and
then rotate it by ? 90º.
Right-to-left
15Solution
16Solution (continue)
Point (10, 10)
Point (30, 25)
17Result
Step-by-step
T(-20, -10)
R(90º)
18Exercises
- Consider the following object
- Apply a rotation by 145º then scale it by Sx2
and Sy1.5 and then translate it by tx20 and
ty-30. - Scale it by Sx½ and Sy2 and then rotate it by
30º. - Apply a rotation by 90º and then another rotation
by 45º. - Apply a rotation by 135º.
19Exercises
- Composite 2D Transformations
- Translation Show that
- Rotation Show that
- Scaling Show that
20General 2D Pivot-Point Rotation
Original position and Pivot Point
Translate Object so that Pivot Point is at origin
Rotation about origin
Translate object so that Pivot Point is return to
position (xr , yr)
21General Pivot-point Rotation
Using Matrices
22Exercises
- Consider the following object
- Apply a rotation by 60 on the Pivot Point (-10,
10) and display it. - Apply a rotation by 30 on the Pivot Point (45,
10) and display it. - Apply a rotation by 270 on the Pivot Point (10,
0) and then translate it by tx -20 and ty 5.
Display the final result.
23General 2D Fixed-Point Scaling
Original position and Fixed Point
Translate Object so that Fixed Point is at origin
Scale Object with respect to origin
Translate Object so that Fixed Point is return to
position (xf , yf)
24General 2D Fixed-Point Scaling
Using Matrices
25Exercises
- Consider the following object
- Scale it by sx 2 and sy ½ relative to the
fixed point (140, 125) and display it. - Apply a rotation by 90 on the Pivot Point (50,
60) and then scale it by sx sy 2 relative to
the Fixed Point (0, 200). Display the result. - Scale it sx sy ½ relative to the Fixed Point
(50, 60) and then rotate it by 180 on the Pivot
Point (50, 60). Display the final result.
26Order of Transformations
27Reflection
About the x axis
About the y axis
28Reflection
Relative to the coordinate origin
With respect to the line y x
292D Shear
Matrix form
302D Shear
- x-direction relative to other reference line
Matrix form
y
312D Shear
Matrix form
322D Shear
- y-direction relative to other reference line
Matrix form
shy ½, xref -1
33Transformations between 2D Coordinate Systems
- To translate object descriptions from xy
coordinates to xy coordinates, we set up a
transformation that superimposes the xy axes
onto the xy axes. This is done in two steps - Translate so that the origin (x0, y0) of the xy
system is moved to the origin (0, 0) of the xy
system. - Rotate the x axis onto the x axis.
34Transformations between 2DCoordinate Systems
35Example
- Find the xy-coordinates of the xy points (10,
20) and (35, 20), as shown in the figure below
36(No Transcript)
37Exercise
- Find the xy-coordinates of the rectangle shown
in the figure below
383D Translation
- Repositioning an object along a straight line
path from one co-ordinate location to another - (x,y,z) (x,y,z)
- To translate a 3D position, we add
translation distances tx ty and tz to the
original coordinates (x,y,z) to obtain the new
coordinate position (x,y) - x x tx , y y ty , z z tz
Matrix form (4 4)
393D Rotation
- z-axis
- The 2D z-axis rotation equations are extended to
3D.
Matrix form
403D Rotation
Matrix form
413D Rotation
Matrix form
423D Scaling
Matrix form
43Other 3D Transformations