Computer Graphics2-Kp
Computer Graphics2-Kp
Basic transformations:
07/30/2021
Translation
Scaling
Rotation
Computer Graphics
Purposes:
To move the position of objects
To alter the shape / size of objects
To change the orientation of objects
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
Two-Dimensional translation
One of rigid-body transformation, which move objects
without deformation
Translate an object by Adding offsets to coordinates to
generate new coordinates positions
Set tx,ty be the translation distance, we have
x' x t x y' y t y
In matrix format, where T is the translation vector
x' x t x
P' P T
y' y t y
P' P T
Computer Graphics
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
We could translate an object by applying the equation to every
07/30/2021
point of an object.
Because each line in an object is made up of an infinite set of points,
however, this process would take an infinitely long time.
Computer Graphics
Fortunately we can translate all the points on a line by translating
only the line’s endpoints and drawing a new line between the
endpoints.
This figure translates the “house” by (3, -4)
TRANSLATION EXAMPLE
07/30/2021
y
Computer Graphics
5
4
(2, 3)
3
1
(1, 1) (3, 1)
0 1 2 3 4 5 6 7 8 9 10 x
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
Two-Dimensional rotation
Rotation axis and angle are specified for rotation r
Convert coordinates into polar form for calculation
r
x r cos y r sin
Example, to rotation an object with angle a
The new position coordinates
x' r cos( ) r cos cos r sin sin x cos y sin
y ' r sin( ) r cos sin r sin cos x sin y cos
In matrix
cos
format sin
R sin cos
P' R P
x' xr ( x xr ) cos ( y yr ) sin
Rotation
y ' yabout
( xapoint
x ) (x
sinr, yr) ( y yr ) cos
r r
Computer Graphics
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
This figure shows the rotation of the house by 45 degrees.
07/30/2021
y
6
Computer Graphics
5
2
1 6
0
1 2 3 4 5 6 7 8 9 10
x
07/30/2021
y
Computer Graphics
5
4
(4, 3)
3
1
(3, 1) (5, 1)
0
1 2 3 4 5 6 7 8 9 10
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
Two-Dimensional scaling
To alter the size of an object by multiplying the coordinates
with scaling factor sx and sy
x' x s x y y sy
In matrix format,
s 0 where
S is a 2by2 scaling matrix
x' x
x
P' S P
y' 0 s y y
x' x s x f (1 s x )
Choosing ax fix point (xf, yf) as its centroid to perform scaling
y' y s y y f (1 s y )
Computer Graphics
BASIC TWO-DIMENSIONAL
GEOMETRIC TRANSFORMATIONS
07/30/2021
In this figure, the house is scaled by 1/2 in x and 1/4 in y
Notice that the scaling is about the origin:
The house is smaller and closer to the origin
Computer Graphics
SCALING
07/30/2021
Ifthe scale factor had been greater than 1, it would be larger and
farther away.
Note: Objects grow and move!
Computer Graphics
y
6
3 6 9
3 3
2
1 2 3
1 1
0
1 2 3 4 5 6 7 8 9 10
x
Note: House shifts position relative to origin
SCALING EXAMPLE
07/30/2021
y
Computer Graphics
5
4
(2, 3)
3
1
(1, 1) (3, 1)
0 1 2 3 4 5 6 7 8 9 10
HOMOGENEOUS COORDINATES
A point (x, y) can be re-written in homogeneous coordinates as
(xh, yh, h)
x' 1 0 t x x
y '
0 1 t y y
1 0 0 1 1
Two-Dimensional rotation matrix
x' cos sin 0 x
y ' sin cos 0 y
1 0 0 1 1
Two-Dimensional
x' s
scaling matrix
0 0 x
x
y' 0 sy 0 y
1 0 0 1 1 © 2005 Pearson Education
INVERSE TRANSFORMATIONS
Inverse translation matrix
1 0 t x
T 1 0 1 t y
07/30/2021
Viewport – An area on a display device to which a
window is mapped is called.
Computer Graphics
- defines where it is to be displayed
159.235
250
Graphics
45
250 x 250
Viewport in Pixels.
Device coords
30
07/30/2021 Computer Graphics
07/30/2021 Computer Graphics
1
Clipping Window
ywmax Normalized Viewport
yvmax
May 2010
xw, yw
xv, yv
ywmin yvmin
0 xvmin xvmax1
xwmin xwmax
Maintain relative size and position between clipping window and viewport.
Construct World-
Modeling World Convert World-
Coordinates Coordinate Scene Coordinates Coordinates to
From Modeling-
Viewing-
Coordinate
Coordinates
Transformations
Viewing Coordinates
(x 1, y 1)
x = x min x = x max
xmin x xmax
ymin y ymax
CLIPPING IN 2D
Need to clip primitives (eg lines) against the sides of the
viewing window
e.g lines or polygons
We only see what is inside the window
159.235 Graphics 39
07/30/2021 Computer Graphics
COHEN-SUTHERLAND CLIPPING
ALGORITHM
Thisis an efficient method of accepting or
rejecting lines that do not intersect the window
edges.
159.235 Graphics 41
COHEN-SUTHERLAND 2D OUTCODES
159.235
1001 1000 1010
Graphics
0001 0000 0010
159.235
1001 1000 1010
Graphics
0001 0000 0010
159.235
1001 1000 1010
Graphics
1000
0001
outcode CompOutCode(
xend , yend
xwmin xwmax
ywmax
x0 , y0 ywmin
May 2010 57
Parametric presentation:
x x0 u xend x0 , y y0 u yend y0 , 0 u 1.
May 2010
A point on the line is cotained in the clipping window iff:
xwmin x0 u xend x0 xwmax ,
ywmin y0 u yend y0 ywmax .
It can be expressed by: upk qk , k 1, 2,3, 4, where
p1 x0 xend , q1 x0 xwmin ;
p2 xend x0 , q2 xwmax x0 .
p3 y0 yend , q3 y0 ywmin ;
p4 yend y0 , q4 ywmax y0 . 58
In the inequality upk qk if pk 0 (pk 0), the
May 2010
u from to + proceeds the line from the ( )
half-plane to () one (with respect to the k -th
border).
occurs at u qk pk .
59
We calculate and update u0 and uend progressively for
May 2010
If pk 0 u0 is calculated since progression is from
May 2010
comparison of qp with qp, and the quotient q p
61
This is more efficient than Cohen-Sutherland Alg,
which computes intersection with clipping window
May 2010
borders for each undecided line, as a part of the
feasibility tests.
62
PSEUDOCODE
Pre-calculate Ni and select PEi for each edge;
for each line segment to be clipped
if P1 = P0 then line is degenerate so clip as a point;
else
begin
tE = 0; tL = 1;
for each candidate intersection with a clip edge
if Ni • D 0 then {Ignore edges parallel to line}
begin
calculate t; {of line and clip edge intersection}
use sign of Ni • D to categorize as PE or PL;
if PE then tE = max(tE,t);
if PL then tL = min(tL,t);
end
if tE > tL then return nil
else return P(tE) and P(tL) as true clip intersections
end
PARAMETRIC LINE-CLIPPING
ALGORITHM
• Introduced by Cyrud and Beck in 1978
• Efficiently improved by Liang and Barsky
• Essentially find the parameter t from P(t) = P0 + (P1-P0)t
64
PARAMETRIC LINE-CLIPPING
ALGORITHM (CONT.)
159.235 Graphics 68
Sutherland-Hodgman Polygon Clipping
Lift Right
Clipper Clipper
69
Sutherland-Hodgman Clipping
Algorithm
159.235
Four cases of polygon clipping:
Graphics
Inside Outside Inside Outside Inside Outside Inside Outside
Output First
Output Second Output
Vertex Intersection Output
Case 1 Case 2. Case 3 Case 4
No
output. 70
SUTHERLAND-HODGMAN ALGORITHM
Input:
v1, v2, … vn the vertices defining the polygon
Single infinite clip edge w/ inside/outside info
Output:
v’1, v’2, … v’m, vertices of the clipped polygon
Do this 4 (or ne) times
Traverse vertices (edges)
Add vertices one-at-a-time to output polygon
Useinside/outside info
Edge intersections
71
SUTHERLAND-HODGMAN ALGORITHM
Can be done incrementally
If first point inside add. If outside, don’t add
72
73
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 74
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 75
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 76
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 77
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
P’ Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 78
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
P’ Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 79
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
P’ Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 80
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
P’ P” Inside
P5 Outside
P3
P4
cgvr.korea.ac.kr 81
CLIPPING TO A BOUNDARY
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2 P1
Window
Boundary
P’ P” Inside
Outside
cgvr.korea.ac.kr 82
Input vertex P Close Polygon entry
Yes
Compute
F=P Intersection I
No
Does SP intersect
No
E?
Output
Yes
vertex I
Compute
Intersection Point
I
Exit
Output
vertex I
S=P
Is S on left
Yes
side of E?
Output
vertex S
NO
Exit
SUTHERLAND-HODGMAN ALGORITHM
84
Note: Edges
XY and ZW!
85
ISSUES WITH SUTHERLAND-HODGMAN
ALGORITHM
86
159.235 Graphics 87
Text Clipping
There are several techniques that can be used to
provide text clipping in a graphics packages.
The choice of clipping method depends on how
characters are generated and what requirements
we have for displaying character strings.
88
Text Clipping
All-or-none string-clipping
• If all of the string is inside a clip window, we keep
it.
• Otherwise the string is discarded.
89
Text Clipping
All-or-none character-clipping
Here we discard only those characters that are not
completely inside the window
90
Text Clipping
Clip the components of individual characters
We treat characters in much the same way that we
treated lines.
If an individual character overlaps a clip window
boundary, we clip off the parts of the character that
are outside the window
91
INPUT DEVICES
Logical Input Devices
Categorized based on functional characteristics.
Each device transmits a particular kind of data.
The different types of data are called input primitives.
Physical Input Devices
Categorized based on the physical machine.
RM [2]-92
LOGICAL INPUT DEVICES
Locator Devices
RM [2]-93
RM
Digitizer
[2]-
94
RM
Joystick and Trackball
[2]-
95
LOGICAL INPUT DEVICES
String Devices
Input Primitive: A string of characters
Example: Keyboard
Applications: Text input
RM [2]-96
LOGICAL INPUT DEVICES
Valuator
Input primitive: Scalar values (typically between 0 and 1).
Examples: Control Dials, Sensing devices, Joysticks
Applications: Input of graphics parameters, Graphics
representation of analog values, Process simulation, Games.
RM [2]-97
LOGICAL INPUT DEVICES
Choice
Input primitive: A selection from a list of options.
Examples: Mouse, Keyboard (Function Keys), Touch Panel
etc
Applications: Interactive menu selection, Program control.
RM [2]-98
LOGICAL INPUT DEVICES
Pick
Input primitive: Selection of a part of the screen.
Examples: Mouse, Cursor Keys, Tablet.
Applications: Interactive editing and positioning.
RM [2]-99
PHYSICAL INPUT DEVICES
Keyboard (input functions: String, Choice, Locator).
Mouse (input functions: Locator, Pick, Choice).
Joystick (input functions: Locator, Valuator).
Knob (Valuator).
Tablet (Locator, Pick).
RM [2]-100
3D INTERACTION DEVICES (RECENT
ADDITIONS)
RM
These devices are used in advanced rendering methods and virtual reality
systems for providing information about three dimensional positions and
motion.Few examples are
1. DATA GLOVES
2. SPACE BALLS
3. IMAGING SENSORS
[2]-
101
3D INTERACTION DEVICES (RECENT
ADDITIONS)
These devices are used in advanced rendering methods and virtual reality
RM
systems for providing information about three dimensional positions and
motion.Few examples are
1. DATA GLOVES
2. SPACE BALLS
3. IMAGING SENSORS
[2]-
102
3D INPUT DEVICES
Gloves
attach electromagnetic tracker to the hand
Pinch gloves
103
UNSUCCESSFUL 3D INPUT DEVICES
Commercial failures
Spaceball
Flymouse
104
SOME CURRENT INPUT DEVICE RESEARCH
105
THREE DIMENSIONAL
GRAPHICS
It is the field of computer graphics that deals with
generating and displaying three dimensional objects
in a two-dimensional space(eg: display screen)
Parallel projection
Project points on the object surface along parallel
lines onto the display plane.
Time-parallel
Time-multiplexed
THREE-DIMENSIONAL AND STEREOSCOPIC VIEWS
THREE-DIMENSIONAL GEOMETRIC AND
MODELING TRANSFORMATIONS
Some Basics
3D Translations.
3D Scaling.
3D Rotation.
3D Reflections.
Transformations.
SOME BASICS
• Basic geometric types.
– Scalars s
– Vectors v
– Points p
• Transformations
– Types of transformation:
– rotation, translation, scale, Reflections, shears.
– Matrix representation
– Order
• P=T(P)
3D Point
We will consider points as column
vectors. Thus, a typical point with
coordinates (x, y, z) is represented as:
x
y
z
3D TRANSLATIONS.
P is translated to P' by T:
1 0 0 tx Called the
0
1 0 ty
translation
T= matrix
0 0 1 tz
0 0 0 1
3D TRANSLATIONS.
x ' 1 0 0 tx x
y ' 0 1 0 t y y
z ' 0
0 1 tz z P' T P
1 0 0 0 1 1
129
3D TRANSLATIONS.
An object is translated in 3D dimensional by
transforming each of the defining points of the
objects.
130
3D TRANSLATIONS.
P is scaled to P' by S:
x' s x 0 0 0 x
P' S P
y ' 0 sy 0 0 y
z' 0 0 sz 0 z
1 0 0 0 1 1
133
3D SCALING
sx 0 0 (1 s x ) x f
0 sy 0 (1 s y ) y f
T ( x f , y f , z f ) S ( s x , s y , s z ) T ( x f , y f , z f )
0 0 sz (1 s z ) z f
0 0 0 1
3D SCALING
3D REFLECTIONS
137
3D SHEARING
• Modify object shapes
• Useful for perspective projections:
– E.g. draw a cube (3D) on a screen (2D)
– Alter the values for x and y by an amount
proportional to the distance from zref
138
3D SHEARING
1 0 shzx shzx z ref
0 1 shzy
shzy z ref
M zshear
0 0 1 0
0 0 0 1
13
9
SHEARS
1 0 a 0
0 1 b 0
SH z
0 0 1 0
0 0 0 1
140
ROTATION
Positive rotation angles produce counterclockwise
rotations about a coordinate axis
141
ROTATION
COORDINATE-AXES ROTATIONS
P ' Rz ( ) P
P ' Rz ( ) P
x yzx
COORDINATE-AXES ROTATIONS
x' 1 0 0 0 x x' x
y ' 0 cos sin 0 y
y ' y sin z cos
z ' 0 sin cos 0 z
z ' y cos z sin
1 0 0 0 1 1
P ' Rx ( ) P
P' R y ( ) P
P' T Rx ( ) T P
1
R( ) T Rx ( ) T
1
Translation, Rotation
y
P1
P1'
Scaling, etc. y
x
z
x
z
150
VISIBLE-SURFACE DETECTION METHODS
Two approaches
Object-space methods: Decide which object, as a whole,
is visible
Image-space methods: The visibility is decided point-
by-point
A-Buffer
Scanline
Depth Sorting
BSP Tree
Area Subdivision
Octree
152
BACK-FACE REMOVAL (CULLING)
Used to remove unseen polygons from convex, closed
polyhedron
153
BACK-FACE REMOVAL (CULLING)
Compute the equation of the plane for each polygon
A point (x,y,z) is behind a polygon surface if
Ax By Cz D 0
Determine back-face
In projection coordinates, we need to consider only the z
component of the normal vector N
Vview N 0
154
DEPTH-BUFFER (Z-BUFFER)
Z-Buffer has memory corresponding to each pixel location
Usually, 16 to 20 bits/location.
155
DEPTH-BUFFER (Z-BUFFER)
Initialize
Each z-buffer location Max z value
Each frame buffer location background color
For each polygon:
Compute z(x,y), polygon depth at the pixel (x,y)
If z(x,y) < z-buffer value at pixel (x,y), then
z buffer(x,y) z(x,y)
pixel(x,y) color of polygon at (x,y)
156
DEPTH CALCULATION
Calculate the z-value on the plane
Ax By D
Ax By Cz D 0 z
C
Incremental calculation
z( x , y ) : the depth of position ( x, y )
A( x 1) By D A
z( x 1, y ) z( x , y )
C C
Ax B( y 1) D B
z( x , y 1) z( x , y )
C C 157
DEPTH-BUFFER (Z-BUFFER)
Advantages/Disadvantages
Lots of memory
Linear performance
Polygons may be processed in any order
Modifications needed to implement antialiasing,
158
DEPTH-BUFFER (Z-BUFFER)
159
ACCUMULATION BUFFER (A-BUFFER)
An extension of the depth-buffer for dealing with
anti-aliasing, area-averaging, transparency, and
translucency
Depth
Surface identifier
161
SCAN LINE METHOD
Intersect each polygon with a particular scanline and solve
hidden surface problem for just that scan line
Requires a depth buffer equal to only one scan line
Requires the entire scene data at the time of scan conversion
162
DEPTH SORTING
We need a partial ordering (not a total ordering) of polygons
The ordering indicates which polygon obscures which
polygon
Some polygons may not obscure each other
Simple cases
163
DEPTH SORTING
We make the following tests for each polygon that has a depth overlap
with S
If any one of these tests is true, no reordering is necessary for S and the
polygon being tested
Polygon S is completely behind the overlapping surface relative to
the viewing position
The overlapping polygon is completely in front of S relative to the
viewing position
The boundary-edge projections of the two polygons onto the view
plane do not overlap
164
DEPTH SORTING
Example
165
DEPTH SORTING
Cyclically overlapping surfaces that alternately obscure
one another
We can divide the surfaces to eliminate the cyclic
overlaps
166