Computer Graphics - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

Computer Graphics

Description:

Computer Graphics Chapter 5 Geometric Transformations Andreas Savva 2D Translation Repositioning an object along a straight line path from one co-ordinate location to ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 44
Provided by: DrAndre77
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics


1
Computer Graphics
  • Chapter 5
  • Geometric Transformations

Andreas Savva
2
2D 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
3
2D Translation
  • Moving a polygon from position (a) to position
    (b) with the translation vector (-5, 10), i.e.

(a)
(b)
4
Translating 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()

5
2D Rotation
  • Repositioning an object along a circular path in
    the xy-plane

The original coordinates are
6
2D Rotation
  • Substituting

Matrix form
7
2D Rotation about a Pivot position
  • Rotating about pivot position (xr, yr)

8
Translating 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)

9
2D Scaling
  • Altering the size of an object. Sx and Sy are the
    scaling factors. If Sx Sy then uniform scaling.

Matrix form
10
2D 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.
11
Translating 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)

12
Matrix Representation
  • Use 33 matrices to combine transformations
  • Translation
  • Rotation
  • Scaling

13
Inverse Transformations
  • Translation
  • Rotation
  • Scaling

14
Example
  • 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
15
Solution
16
Solution (continue)
Point (10, 10)
Point (30, 25)
17
Result
Step-by-step
T(-20, -10)
R(90º)
18
Exercises
  • 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º.

19
Exercises
  • Composite 2D Transformations
  • Translation Show that
  • Rotation Show that
  • Scaling Show that

20
General 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)
21
General Pivot-point Rotation
Using Matrices
22
Exercises
  • 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.

23
General 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)
24
General 2D Fixed-Point Scaling
Using Matrices
25
Exercises
  • 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.

26
Order of Transformations
27
Reflection
About the x axis
About the y axis
28
Reflection
Relative to the coordinate origin
With respect to the line y x
29
2D Shear
  • x-direction shear

Matrix form
30
2D Shear
  • x-direction relative to other reference line

Matrix form
y
31
2D Shear
  • y-direction shear

Matrix form
32
2D Shear
  • y-direction relative to other reference line

Matrix form
shy ½, xref -1
33
Transformations 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.

34
Transformations between 2DCoordinate Systems
  • i.e.
  • 1)
  • 2)
  • Concatenating

35
Example
  • Find the xy-coordinates of the xy points (10,
    20) and (35, 20), as shown in the figure below

36
(No Transcript)
37
Exercise
  • Find the xy-coordinates of the rectangle shown
    in the figure below

38
3D 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)
39
3D Rotation
  • z-axis
  • The 2D z-axis rotation equations are extended to
    3D.

Matrix form
40
3D Rotation
  • x-axis

Matrix form
41
3D Rotation
  • y-axis

Matrix form
42
3D Scaling
Matrix form
43
Other 3D Transformations
  • Reflection z-axis
  • Shears z-axis
Write a Comment
User Comments (0)
About PowerShow.com