Professional Documents
Culture Documents
CGV Mod2 Shankar
CGV Mod2 Shankar
Transformation
3/13/2020 1
Viewing
• Transformation worldscreen
• Clipping: Removing parts outside screen
3/13/2020 2
Clipping Window
ywmax
World Coordinates
xwmin xwmax
Viewing world has its own
Viewport
coordinates, which may be
yvmax
a non-uniform scaling of
world coordinates.
yvmin
Viewport Coordinates
xvmin xvmax
3/13/2020 3
2D viewing transformation pipeline
Construct World-
Modeling World Convert World-
Coordinate Scene
Coordinates Coordinates Coordinates to
From Modeling-
Viewing-
Coordinate
Coordinates
Transformations
Viewing Coordinates
3/13/2020 4
2D Viewing pipeline
World: Screen:
Clipping window Viewport
ywmax yvmax
ywmin yvmin
3/13/2020 5
2D Viewing pipeline
World: Screen:
Clipping window Viewport
ywmax yvmax
ywmin yvmin
Clipping window:
Panning…
3/13/2020 6
2D Viewing pipeline
World: Screen:
Clipping window Viewport
ywmax yvmax
ywmin yvmin
Clipping window:
Panning…
3/13/2020 7
2D Viewing pipeline
World: Screen:
Viewport
ywmax yvmax
ywmin yvmin
Clipping window:
Zooming…
3/13/2020 8
2D Viewing pipeline
World: Screen:
ywmax Viewport
yvmax
yvmin
ywmin
xwmin xwmax xvmin xvmax
Clipping window:
Zooming…
3/13/2020 9
2D Viewing pipeline
MC: Modeling Coordinates
Apply model transformations
WC: World Coordinates
Determine visible parts
VC: Viewing Coordinates
To standard coordinates
NC: Normalized Coordinates
Clip and determine pixels
DC: Device Coordinates
3/13/2020 10
Window to Viewport
Transformation
• What is window?
3/13/2020 11
Window to Viewport
Transformation
• What is viewport?
3/13/2020 12
3/13/2020 13
3/13/2020 14
3/13/2020 15
leave some 4 lines gap here
3/13/2020 16
3/13/2020 17
3/13/2020 18
3/13/2020 19
Similarly, do for Yv
3/13/2020 20
3/13/2020 21
3/13/2020 22
3/13/2020 23
3/13/2020 24
Now, go back to that gap...
3/13/2020 25
Apparently, in 5th lab program (cohen
Sutherland line clip)
3/13/2020 26
Clipping window
Clipping window
ywmax
ywmax ywmin
ywmin
xwmax-xwmin xvmax-xvmin
Scale with :
xvmax xvmin yvmax yvmin
S ,
xwmax xwmin ywmax ywmin
If the two scale factors are unequal,
then the aspect - ratio changes : distortion !
3/13/2020 28
To normalized coordinates
1 Viewport
yvmax
yvmax -yvmin
yvmin
Translate with :
Txvmin , yvmin
3/13/2020 29
To normalized coordinates
Clipping window 1 Viewport
ywmax yvmax
ywmin yvmin
3/13/2020 30
OpenGL 2D Viewing
Specification of 2D Viewing in OpenGL:
- Standard pattern, follows terminology.
glMatrixMode(GL_PROJECTION);
3/13/2020 31
OpenGL 2D Viewing
Next, specify the 2D clipping window:
gluOrtho2D(xwmin, xwmax, ywmin, ywmax);
ywmax
ywmin
xwmin xwmax
3/13/2020 32
OpenGL 2D Viewing
Finally, specify the viewport:
glViewport(xvmin, yvmin, vpWidth, vpHeight);
vpHeight
vpWidth
(xvmin, yvmin)
3/13/2020 33
OpenGL 2D Viewing
In short:
glMatrixMode(GL_PROJECTION);
gluOrtho2D(xwmin, xwmax, ywmin, ywmax);
glViewport(xvmin, yvmin, vpWidth, vpHeight);
3/13/2020 34
OpenGL 2D viewing functions
• glMatrixMode(GL_PROJECTION);
• glLoadIdentity();
• glMatrixMode(GL_MODELVIEW);
• gluOrtho2D(xwmin, xwmax, ywmin, ywmax);
• glViewport(xvmin, yvmin, vpWidth, vpHeight);
• glGetIntegerv (GL_VIEWPORT, vpArray);
• glutInit(&argc,argv);
• glutInitWindowPosition(10,10);
• glutInitWindowSize(500,500);
• glutCreateWindow(“My First”);
• glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
• windowID = glutCreateWindow(“My First”);
• glutDestroyWindow(windowID);
3/13/2020 35
OpenGL 2D viewing functions
• glutSetWindow(windowID);
• currentWindowID = glutGetWindow();
• glutReshapeWindow(width,height); //reset
• glutFullScreen();
• glutReshapeFunc(reshapeFunction);
• glitIconifyWindow();
• glutSetIconTitle(“Icon Name”);
• glutSetWindowTitle(“New Window Name”);
• glutSetWindow (windowID);
• glutPopWindow ( );
• glutSetWindow (windowID);
• glutPushWindow ( );
• glutHideWindow ( );
3/13/2020 36
OpenGL 2D viewing functions
• glutShowWindow ( );
• glutCreateSubWindow (windowID,
xBottomLeft, yBottomLeft,width, height);
• glutDisplayFunc (pictureDescrip);
• glutPostRedisplay ( );
• glutMainLoop ( );
3/13/2020 37
Module-2
2D Geometric Transformations
3/13/2020 1
2D Transformations
3/13/2020 2
Why Transformations ?
3/13/2020 3
• Translation
• Rotation
3/13/2020 4
• Scaling
• Uniform Scaling
• Un-uniform Scaling
3/13/2020 5
• Reflection
• Shear
3/13/2020 6
Translation
• A translation moves all points
in an object along the same
straight-line path to new
positions.
• The path is represented by a P'(8,6)
vector, called the translation or
shift vector.
• We can write the components: ty=4
p'x = px + tx
p'y = py + ty P(2, 2) tx= 6
• or in matrix form:
P' = P + T
x' x tx
y' = y + ty
3/13/2020 7
Rotation
• A rotation repositions
all points in an object
along a circular path in P
the plane centered at
the pivot point.
3/13/2020 8
Rotation
• Review Trigonometry
=> cos = x/r , sin = y/r
• x = r. cos , y = r.sin
P’(x’, y’)
P’(x’, y’)
• or in matrix form:
P' = R • P
• can be clockwise (-ve) or
counterclockwise (+ve as our
example). y’
P(x,y)
• Rotation matrix
r
cos sin y
R
sin cos x’ x
3/13/2020 10
Scaling
• Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x-
and y- coordinates P’
respectively.
• Scales are about the origin.
• We can write the components:
p'x = sx • px
P
p'y = sy • py
or in matrix form:
P' = S • P
Scale matrix as:
sx 0
S
0 s y
3/13/2020 11
Scaling
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
3/13/2020 12
Scaling
• If the scale factors are in between 0
and 1 the points will be moved
P’
closer to the origin the object
will be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
3/13/2020 13
Scaling
P’
3/13/2020 14
Matrix Representations &
Homogenous Coordinates
3/13/2020 15
3/13/2020 16
Problem: Rotate the given Triangle by 90 degrees about the origin
3/13/2020 17
Problem: Prove that successive translations are additive
3/13/2020 18
Problem: Prove that successive scaling is multiplicative
3/13/2020 19
General pivot point rotation
• Translate the object so that pivot-position is moved to the
coordinate origin
• Rotate the object about the coordinate origin
• Translate the object so that the pivot point is returned to its
original position
(xr,yr)
(xf,yf)
(a) (b)
Translation of (c) (d)
Original
Position of object so that scaling was Translation of the
Object and fixed point about origin object so that the
Fixed point (xf,yf)is at Fixed point is
origin returned to position
3/13/2020 21
(xf,yf)
Composite Transformations
(A) Translations
If two successive translation vectors (tx1,ty1) and (tx2,ty2) are applied to
a coordinate position P, the final transformed location P’ is calculated
as: -
P’=T(tx2,ty2) . {T(tx1,ty1) .P}
={T(tx2,ty2) . T(tx1,ty1)} .P
Where P and P’ are represented as homogeneous-coordinate column
vectors. We can verify this result by calculating the matrix product for
the two associative groupings. Also, the composite transformation
matrix for this sequence of transformations is: -
1 0 tx2 1 0 tx1 1 0 tx1+tx2
0 0 1 0 0 1 0 0 1
3/13/2020 23
(C) Scaling
Concatenating transformation matrices for two successive scaling
operations produces the following composite scaling matrix: -
3/13/2020 24
2D Composition Problems
THEORY
3/13/2020 25
PROBLEM 1
problem Step 1
Step 3
Step 2
3/13/2020 26
3/13/2020 27
3/13/2020 28
THEORY
3/13/2020 29
PROBLEM 2
3/13/2020 30
Other transformations
• Reflection is a transformation that produces a mirror image of
an object. It is obtained by rotating the object by 180 deg about
the reflection axis
1 0 0
2 3
2’ 3’ 0 -1 0
0 0 1
1’
Reflected position
3/13/2020 31
Reflection
-1 0 0
0 1 0
0 0 1
3/13/2020 32
Reflection
Reflection of an object relative to an axis perpendicular to
the xy plane and passing through the coordinate origin
Y-axis
-1 0 0
Reflected position 0 -1 0
3’
0 0 1
2’
0 1 0
Y-axis
Original position 1 0 0
3
0 0 1
2 1
1’
3’
Reflected position
2’
Origin O X-axis
(0,0)
3/13/2020 34
Reflection of an object w.r.t the
Y-axis
straight line y=-x
0 -1 0
-1 0 0
0 0 1
X-axis
Origin 2
O (0,0) 3
Original position
1
1’
2’ Line Y = - X
3’
3/13/2020 Reflected position 35
Reflection of an arbitrary axis
y=mx+b
Original position
3
2 1
3/13/2020 36
Original position Translation so that it passes through origin
3 Rotate so that it coincides with x-
Original position axis and reflect also about x-axis
3
2 1
2 1
Original position
2 3
1
1’
Rotate back Translate back
Original position
Original position 3 Reflected position
3
2’ 3’
2
2 1 1
1’ Reflected position
1’
3’ 3’
2’ Reflected position
2’
3/13/2020 37
Shear Transformations
3/13/2020 38
Shears
1 0 0 1 shx 0
shy 1 0 0 1 0
0 0 1 0 0 1
3/13/2020 39
An X- direction Shear
For example, Shx=2
(2,1) (3,1)
(0,1) (1,1)
3/13/2020 40
An Y- direction Shear
For example, Shy=2
Y Y (1,3)
(1,2)
X X
(0,0) (1,0) (0,0)
3/13/2020 41
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner