0% found this document useful (0 votes)
45 views130 pages

Chapter 3 &4 CG

Chapter 3 discusses two-dimensional viewing in computer graphics, focusing on the viewing pipeline, window-to-viewport transformation, and polygon clipping techniques. It covers concepts such as viewing coordinate reference frames, clipping algorithms like Cohen-Sutherland and Liang-Barsky, and the importance of maintaining object proportions during transformations. The chapter emphasizes the processes involved in mapping world coordinates to device coordinates and the methods for clipping graphical objects effectively.

Uploaded by

selemunabrha276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views130 pages

Chapter 3 &4 CG

Chapter 3 discusses two-dimensional viewing in computer graphics, focusing on the viewing pipeline, window-to-viewport transformation, and polygon clipping techniques. It covers concepts such as viewing coordinate reference frames, clipping algorithms like Cohen-Sutherland and Liang-Barsky, and the importance of maintaining object proportions during transformations. The chapter emphasizes the processes involved in mapping world coordinates to device coordinates and the methods for clipping graphical objects effectively.

Uploaded by

selemunabrha276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter 3: Two Dimensional

viewing

DEP ’ T: CSE I V
C O UR SE: C O MPUTER G R A PHI CS
I NSTR UC TO R : W I DA SSI E (MSC )
MEKEL L E I NSTI TUTE O F TEC HNO LO GY- MEKEL L E UNI V ER SI TY
Two Dimensional Viewing
The viewing Pipeline

Viewing Coordinate Reference Frame

Window to View port transformation


Polygon clipping
The Sutherlan Hodgman Algorithm,
Weiler Atherton Polygon Clipping,
Character and Text Clipping
The Viewing Pipelined
As an example:
Assume a map designer using a computer-aided design(CAD)
system wants to draw a map for any country.
The best coordinate system might be one with the origin in the
middle of the map and coordinate values ranging from –1000 to 1000
in both the horizontal and vertical directions.
Furthermore, while drawing some parts of the map, the designer
may want to work with an enlarged display of those parts.
The Viewing Pipelined
A world-coordinate area selected for display is called a window (defines what
is to be viewed).
An area on a display device to which a window is mapped is called a viewport
(defines where it is to be displayed).
Often, windows and viewports are rectangles in standard position, with the
rectangle edges parallel to the coordinate axes.
Other window or viewport geometries, such as general polygon shapes and
circles, are used in some applications, but these shapes take longer to process.
The Viewing Pipelined
The mapping of a part of a world-coordinate scene to device coordinates is
referred to as a viewing transformation.
2D viewing transformation is simply referred to as the window-to-viewport
transformation or the windowing transformation.
The Viewing Pipelined
The viewing transformation is carry out in several steps, as shown in the figure.

Construct the scene in world coordinate (WC) using the output primitives such
as line and circle and their attributes.
Obtain a particular orientation for the window, set up a two-dimensional viewing
coordinate (VC) system in the world coordinate plane, and define a window in the
viewing coordinate system.
The Viewing Pipelined
The viewing – coordinate reference frame is used to provide a method for
setting up arbitrary orientations for rectangular windows. Once the viewing
reference frame is established, we can transform descriptions in world
coordinates (WC) to viewing coordinates (VC).
We then define a viewport in normalized coordinates (NVC) (in the range
from 0 to 1) and map the viewing – coordinate description of the scene to
normalized– coordinate.

The Viewing Pipelined
At the final step, all parts of the picture that lie outside the viewport are
clipped, and the contents of the viewport are transferred to device coordinates
(DC).

A rotated viewing-coordinate reference frame and the mapping to normalized


coordinates
The Viewing Pipelined
By changing the position of the window, we can view objects at different
positions on the display area of an output device
By varying the size of viewports, we can change the size and proportions of the
displayed objects. We achieve zooming effects by successively mapping
different-sized windows on a fixed-size viewport
As the windows are made smaller, we zoom in on some part of a scene to view
details that are not shown with larger windows
The Viewing Pipelined
Similarly, more overview is obtained by zooming out from a section of a scene
with successively larger windows
Panning effects are produced by moving a fixed-size window across the
various objects in a scene.
The Viewing Pipelined
Viewports are typically defined within the unit square (normalized
coordinates). This provides a means for separating the viewing and other
transformations from specific output-device requirements, so that the graphics
package is largely device-independent
Once the scene has been transferred to normalized coordinates, the unit square
is simply mapped to the display area for the particular output device in use at that
time. Different output devices can be used by providing the appreciate device
derivers
The Viewing Pipelined
Viewing Coordinate Reference Frame
To obtain the matrix for converting world-coordinate positions to viewing
coordinates:
First, we translate the viewing origin to the world origin.
Second, we rotate the two coordinate reference frames.

Mwc, vc = R.T
Where T is the translation matrix and R is the rotation matrix
The Viewing Pipelined
1 0 –x0
T(–x0, –y0) = 0 1 –y0
0 0 1

cos  sin  0
R(–) = – sin  cos  0
0 0 1
Where  is the orientation angle between the xworld and xview axes.
The Viewing Pipelined
Window to Viewport Coordinate Transformation
The Viewing Pipelined
Window to Viewport Coordinate Transformation
Solving these expressions for the viewport position (xv, yv), we have
xv = xvmin + (xw – xwmin)sx
yv = yvmin + (yw – ywmin)sy ……………………………………………..
Equation 1

where the scaling factors are


sx = xvmax – xvmin / xwmax – xwmin
sy = yvmax – yvmin / ywmax – ywmin
The Viewing Pipelined
Window to Viewport Coordinate Transformation
Equation 1 can also be derived with a set of transformations that coverts the
window area into the viewport area:
1. Perform a scaling using a fixed-point position of (xwmin, ywmin) that scales the
window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport.
The Viewing Pipelined
Window to Viewport Coordinate Transformation
Relative proportions of the objects are maintained if the scaling factors are the
same (sx = sy).
Otherwise world objects will be stretched or contracted in either the x or y
direction when displayed on the output device.
Clipping Operations
Clipping Algorithm: Identifies those portions of a picture that are
either inside or outside of a specified region of space
Clip Window: The region against which an object is to be clipped
Point Clipping
Line Clipping (straight-line segments)
Area Clipping (polygons)
Text Clipping
Point Clipping
Clip window: rectangle, edges of the clip window (xwmin, xwmax,
ywmin, ywmax)
If xwmin  x  xwmax
ywmin  y  ywmax
Then
The point p = (x, y) is saved for display
Otherwise: the point is clipped (not saved for display)
Line Clipping
Line clipping against a rectangular window

before clipping after clipping


Line Clipping
inside – outside test:
Completely Inside: A line with both endpoints inside all clipping boundaries,
such as the line from p1 to p2, is saved.
Completely Outside: A line with both endpoints outside any one of the clip
boundaries, such as the line from p3 to p4, is not saved.
If the line is not completely inside or completely outside, we must perform
intersection calculations with one or more clipping boundaries.
Line Clipping
A line segment with endpoints (x1, y1) and (x2, y2) and one or both endpoints
outside the clipping rectangle, the parametric representation
x = x1 + u ( x2 – x1)
y = y1 + u ( y2 – y1), 0u1
 If the value of u for an intersection with a rectangle boundary edge is outside
the range 0 to 1, the line does not intersect with that boundary.
If the value of u is within the range from 0 to 1, the line segment intersect with
that boundary.
Line Clipping
Solve u by substitute x = xwmax in
◦ x = x1 + u (x2 – x1)
◦ 5 = 4 + u (7 – 4)
◦ u = 1/3
The value of u is within the range from 0 to 1, the line segment intersects with
the boundary xwmax
 Solve y by substitute u in y = y1 + u ( y2 – y1)
y = 2 + 1/3 (3 – 2) = 2.33
Intersection point at xwmax is (5, 2.33)
Cohen-Sutherland Line
Clipping
This method speeds up the processing of the line segment by performing initial
tests that reduce the number of intersections that must be calculated.
Every line endpoint in a picture is assigned a four-digit binary code, called
region code that identifies the location of the point relative to the boundaries of
the clipping rectangle.

24
Cohen-Sutherland Line
Clipping
1001 1000 1010

Window
0001 0000 0010

0101 0100 0110

Bit 4 Bit 3 Bit 2 Bit 1


Above Below Right Left
25
Cohen-Sutherland Line
Clipping
Region-code bit values can be determined as follows:
Bit 1 is the sign bit of x – xwmin
Bit 2 is the sign bit of xwmax – x
Bit 3 is the sign bit of y – ywmin
Bit 4 is the sign bit of ywmax – y
If the sign is negative the bit is set to 1
otherwise is set to 0.

26
Cohen-Sutherland Line
Clipping
Any lines that has a region code of 0000 for both endpoint are completely inside, we save
these lines.
Any lines that have a 1 in the same bit position in the region-codes for each endpoint are
completely outside and we reject these lines.
A method that can be used to test lines for total clipping is to perform the logical AND
operation with both region codes. If the result is not 0000, the line is completely outside the
clipping region.

27
Cohen-Sutherland Line
Clipping
p1 0100
p2 1001
p3 0001
p4 0100
p1 AND p2 =0000
p3 AND p4 =0000

28
Cohen-Sutherland Line
Clipping
For a line with endpoint (x1, y1) and (x2, y2)

m = (y2 – y1) / (x2 – x1)


Intersection points with the clipping boundary:
The intersection with vertical boundary (x=xwmin or x=xwmax), the y coordinate can be
calculated as:
y = y1 + m(x – x1)

The intersection with a horizontal boundary (y=yw or y=ywmax.), the x


min

coordinate can be calculated as


x = x1 + (y – y1) / m

29
Cohen-Sutherland Line
Clipping (Example)

30
Liang-Barsky Line Clipping
Algorithm
For a line segment with endpoints (x1, y1) and (x2, y2), we can describe the line with parametric
form:
x = x1 + u x
y = y1 + u y, 0 u 1
where x= x2 – x1 and y= y2– y1
The point-clipping condition in the parametric form:
xwmin  x1 + u x  xwmax
ywmin  y1 + u y  ywmax

31
Liang-Barsky Line Clipping
Algorithm
xwmin  x1 + u x  xwmax
ywmin  y1 + u y  ywmax
Each of these four inequalities can be expressed as:
upk  qk, k=1, 2, 3, 4
where the parameters p and q are defined as:
p1 = – x, q1 = x1 – xwmin
p2 = x, q2 = xwmax – x1
p3 = – y, q3 = y1 – ywmin
p4 = y, q4 = ywmax – y1

32
Liang-Barsky Line Clipping
Algorithm
Any lines that is parallel to one of the clipping boundaries has pk=0 for the value of k
corresponding to that boundary where k = 1, 2, 3, 4 correspond to left, right, bottom and top
boundaries respectively.
If, for that value of k, we also find qk < 0, then the line is completely outside the boundary and
can be eliminated from further consideration.
If qk  0, then the line is inside the parallel clipping boundary.

33
Liang-Barsky Line Clipping
Algorithm
If pk < 0, the infinite extension of the line proceeds from the outside to the inside of the infinite
extension of this clipping boundary.
If pk > 0, the line proceeds from the inside to the outside.
For a nonzero value of pk (pk  0), we can calculate the value of u that corresponds to the point
where the infinitely extended line intersects the extension of boundary k as:
u = q k / pk

34
Liang-Barsky Line Clipping
Algorithm
For each line, we can calculate values for parameters u1 and u2 that define that part of the line
that lies within the clip rectangle.
The value of u1 is determined by looking at the rectangle edges for which the line proceeds
from outside to the inside (pk < 0).
For these edges, we calculate rk = qk / pk.
The value of u1 is taken as the largest of the set consisting of 0 and the various values of r.

35
Liang-Barsky Line Clipping
Algorithm
The value of u2 is determined by examining the boundaries for which the line proceeds from
inside to the outside (pk > 0).
A value of rk is calculated for each of these boundaries, and the value of u2 is the minimum of
the set consisting of 1 and the calculated r values.

36
Liang-Barsky Line Clipping
Algorithm
If u1 > u2, the line is completely outside the clip window and it can be discarded.
Otherwise, the endpoints of the clipped line are calculated from the two values of parameter u.

37
Liang-Barsky Line Clipping
Algorithm
The Liang-Barsky Line Clipping Algorithm can be summarized as follows:
1.For each line, calculate the parameters p, q and r:
p1 = – x, q1 = x1 – xwmin, r1 = q1/ p1
p2 = x, q2 = xwmax – x1 , r2 = q2/ p2
p3 = – y, q3 = y1 – ywmin, r3 = q3/ p3
p4 = y, q4 = ywmax – y1, r1 = q4/ p4

38
Liang-Barsky Line Clipping
Algorithm
The Liang-Barsky Line Clipping Algorithm can be summarized as follows:
2.Determine the value of u1 is by looking at the rectangle edges for which the line proceeds from
outside to the inside (pk < 0). The value of u1 is taken as the largest of the set consisting of 0 and
the various values of r.
3. Determine the value of u2 by examining the boundaries for which the line proceeds from inside
to the outside (pk > 0). A value of rk is calculated for each of these boundaries, and the value of
u2 is the minimum of the set consisting of 1 and the calculated r values.

39
Liang-Barsky Line Clipping
Algorithm
The Liang-Barsky Line Clipping Algorithm can be summarized as follows:
4.If u1 > u2, the line is completely outside the clip window and it can be discarded.
5. Otherwise, the endpoints of the clipped line are calculated from the two values of parameter u.
 If u2 <1 x= x1+u2 x, y = y1 +u2 y
 Otherwise x = x2, y = y2
 If u1 >0 x= x1+u1 x, y = y1 +u1 dy
 Otherwise x = x1, y = y1

40
Liang-Barsky Line Clipping Algorithm
(Example)

41
Area Clipping (polygons)
To clip a polygon, we cannot directly apply a line-clipping method to the individual polygon
edges because this approach would produce a series of unconnected line segments as shown in
figure

For polygon clipping, we require an algorithm that will generate one or more closed areas that
are then scan converted for the appreciate area fill
The output of a polygon clipper should be a sequence of vertices that defines the clipped
polygon boundaries

42
Sutherland-Hodgman Polygon Clipping

Clip a polygon by processing the polygon boundary as a whole against each


window edge.
Processing all polygon vertices against each clip rectangle boundary in turn.
Beginning with the initial set of polygon vertices, we could first clip the
polygon against the left rectangle boundary to produce a new sequence of
vertices.
The new set of vertices could be successively passed to a right boundary
clipper, a bottom boundary clipper, and a top boundary clipper, a right boundary
clipper.

43
Sutherland-Hodgman Polygon Clipping

Lift Right
Clipper Clipper

Bottom
At each step, a new sequence of output Clipper
vertices is generated and passed to the
next window boundary clipper.
Top
Clipper

44
Sutherland-Hodgman Polygon Clipping

There are four possible cases when processing vertices in sequence around the
perimeter of a polygon.
As each pair of adjacent polygon vertices is passed to a next window boundary
clipper, we make the following tests

45
Sutherland-Hodgman Polygon Clipping

1.If the first vertex is outside the window boundary and the second vertex is
inside
Then , both the intersection point of the polygon edge with the window
boundary and the second vertex are added to the output vertex list.

46
Sutherland-Hodgman Polygon Clipping

2.If both input vertices are inside the window boundary.


Then, only the second vertex is added to the output vertex list.

47
Sutherland-Hodgman Polygon Clipping

3.If the first vertex is inside the window boundary and the second vertex is
outside.
Then, only the edge intersection with the window boundary is added to the
output vertex list.

48
Sutherland-Hodgman Polygon Clipping

4.If both input vertices are outside the window boundary.


Then, nothing is added to the output vertex list.

49
Sutherland-Hodgman Polygon
Clipping (Example)

We illustrate this algorithm by processing the area in figure against the left window
boundary.
Vertices 1 and 2 are outside of the boundary.
Vertex 3, which is inside, 1' and vertex 3 are saved.
Vertex 4 and 5 are inside, and they also saved.
Vertex 6 is outside, 5' is saved.
Using the five saved points,
we would repeat the process for the next window boundary.

50
Sutherland-Hodgman Polygon
Clipping

The Sutherland-Hodgman algorithm correctly clips convex polygons, but concave


polygons may be displayed with extraneous lines as demonstrated in figure.
Since there is only one output vertex list, the last vertex in the list is always joined to
the first vertex.

51
Weiler-Atherton Polygon Clipping

This algorithm was developed for identifying visible surfaces, and can be used to
clip a fill area that is either a convex polygon or a concave polygon.
The basic idea of this algorithm is that instead of proceeding around the polygon
edges as vertices are processed, we will follow the window boundaries.
The path we follow depends on:
polygon-processing direction (clockwise or counterclockwise)
The pair of polygon vertices: outside-to-inside or an inside-to-outside.

52
Weiler-Atherton Polygon Clipping

For clockwise processing of polygon vertices, we use the following rules:


For an outside-to-inside pair of vertices, follow polygon boundaries.
For an inside-to-outside pair of vertices, follow window boundaries in a clockwise
direction

53
Weiler-Atherton Polygon Clipping
(Example)

54
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.

55
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.

56
Text Clipping

All-or-none character-clipping
Here we discard only those characters that are not completely inside the
window

57
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

58
3D Viewing Pipeline
59
Primitives
Object space
Modeling Transformation

World space
Viewing Transformation
Camera space

Hidden Surface Removal

Lighting & Shading

3D-Clipping

Projection
Normalized view space
Scan conversion, Hiding
Image space,
Device coordinates
Image
60 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
61 3D Coordinate System
 3D coordinate system consists of a reference point called
origin and three mutually perpendicular passing through
origin. y axis

z
x

z axis x axis Right-Hand


Reference System
62 3D Coordinate System

 A point P(x,y,z) specifies that point y axis

is
 At a distance of x units from YZ-plane y
 At a distance of y units from XZ-plane
 At a distance of z units from XY-plane
P

z
x

z axis x axis
63 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
64 Vector Fundamentals
 In 3D there are 3 natural coordinate vectors I, J and K having
unit along X, Y and Z axis respectively.

y axis

• Any vector V = aI+bJ+cK can be


y V=aI+bJ+cK
resolved into three components
(a,b,c) that represent corresponding
point when the tail of V is placed at P (a,b,c)
the origin.
z
x

z axis x axis
65 Vector Fundamentals
 If P(x0,y0,z0) and Q(x1,y1,z1) are two points in space then
PQ = (x1 – xo)I+ (y1 – yo)J+ (z1 – zo)K
y axis

 Vector has two attributes: y V=aI+bJ+cK

 length- a scalar denoted by |v|


 direction in 3D space P (a,b,c)

 Equality: Two vectors are equal if


z
they have same length and direction x
z axis
x axis
66 Vector Fundamentals

1. Vector Addition: perform addition by the head-to-tail rule.


Note u+v = v+u
u
v v+u
u+v
u
67 Vector Fundamentals

2. Vector Subtraction: To perform subtraction, given u and v, we


define u - v to be u + (-v):
Note u - v ≠ v – u

u u -v
v
u-v
Vector Fundamentals
68

3. Zero Vector: i.e. vector with zero length and no direction.


v + (-v) = 0
4. Magnitude of Vector of a vector u = aI+bJ+cK is a scalar
quantity defined as:
2 2 2
u  a b c

5. Unit vector for any vector u is a vector having direction of u


and unit magnitude. It can be found as v
u -v
uv 
u
69 Vector Fundamentals

6. Scalar Multiplication: (Scalar times a vector ) Let  be a scalar


and u a vector we define u to be the vector with length |  ||u|
with
 the direction of u if  > 0
 the opposite of u if  < 0

if  = 0, the vector is the zero vector or a point.

u 2u
-3u
70 Vector Fundamentals

7. Dot Product: Given two vectors u = a1I+b1J+c1K and v = a2I+b2J+c2K


the dot product of the vectors is defined to be the scalar as follows
u.v = a1.a2+b1. b2+c1.c2
or u.v = |u| |v| cos  , 0 ≤≤
where  is the angle between u and v
Also
cos  = u.v /|u| |v|
Or  = cos-1(u.v /|u| |v|) v
θ
u
71 Vector Fundamentals

The dot product is a scalar value that tells us something about


the relationship between two vectors
 If u·v > 0 then 0<θ < 90º
 Vectors point in the same general direction

 If u·v < 0 then θ > 90º


 Vectors point in opposite direction

 If u·v = 0 then θ = 90º


 Vectors are perpendicular
 (or one or both of the vectors is degenerate (0,0,0))
72 Vector Fundamentals

8. Cross Product: Given two vectors u = a1I+b1J+c1K and v =


a2I+b2J+c2K the cross product of the vectors is defined to be the
new vector whose length is |u||v| sin , 0 ≤≤ and direction is
given by the right hand rule.
u x v = (b1.c2 – c1. b2)I+ (c1.a2 – a1. c2)J+ (a1.b2 – b1. a2)K
u
or |u x v| = |u| |v| sin  , 0 ≤≤ where  is the angle b/w u & v
v
sin  = |u x v| /|u| |v|
uXv
Or  = sin-1(|u x v| /|u| |v|)
73 Vector Fundamentals

 In a Right handed coordinate System J

 IxJ=K
 JxK=I
 I x K = -J
or K x I = J
K I

Right-Hand
Reference System
74 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
75 3D Homogeneous Coordinates
 Similar to the 2-D situation we can use homogeneous
coordinates for 3-D transformations - 4 coordinate
y axis
column vector

y
 All transformations can
then be represented
as matrices  x  P
y
P(x, y, z) =  
 z
 
 1 z
x

z axis x axis
76 3D Homogeneous Coordinates
 Transform a point:

 px   mxx mxy mxz d x   px   mxx px  mxy py  mxz pz  d x 


 p   m myy myz d y   py   myx px  myy py  myz pz  d y 
 y    yx     
 pz   mzx mzy mzz dz   pz   mzx px  mzy py  mzz pz  dz 
      
1  0 0 0 1 1   0  0  0 1 

 px 
  
M  py   d
 pz 

 Top three rows are the affine transform!


 Bottom row stays 1
77 3D Homogeneous Coordinates
 Transform a vector:
 vx   mxx mxy mxz d x   vx   mxx vx  mxy vy  mxz vz  0 
 v   m myy myz d y   vy   myx vx  myy vy  myz vz  0 
 y    yx     
 vz   mzx mzy mzz dz   vz   mzx vx  mzy vy  mzz vz  0 
      
 0  0 0 0 1 0  0000 

 vx 
 
M  vy 
 vz 

 Top three rows are the linear transform


 Displacement d is properly ignored
 Bottom row stays 0
78 3D Homogeneous Coordinates
 In Homogeneous arithmetic Legal operations always end in
0 or 1!      
vector+vector:  0   0   0
     
     
vector-vector:  0   0   0
     
   
scalar*vector: s    
 0  0
     
point+vector:  1   0   1
     
     
point-point:  1   1   0 
     
     
point+point:  1   1   2
     
   
scalar*point: s    
 1  s
 weighted average  1   2    
  of points:  
 affine combination  3 1
 3 
 1
 1
 
79 3D Homogeneous Coordinates
 Rotation, Scale, and Translation of points and vectors
unified in a single matrix transformation:

p M p  mxx mxy mxz dx 


m myy myz dy 
Where M
 =yx 
 mzx mzy mzz dz 
 
 0 0 0 1
 Matrix has the form:
 Last row always 0,0,0,1

 Transforms compose by matrix multiplication.


80 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
3D Geometric Transformations
82

 Geometric Transformations: In Geometric transformation an


object itself is moved relative to a stationary coordinate system
or background. The mathematical statement of this view point is
described by geometric transformation applied to each point of
the object. Various Geometric transformations are:

 Translation
 Scaling
 Rotation
 Reflection
 Shearing
83 3D Geometric Transformations
 Once we have an object described, transformations are used
to move that object, scale it and rotate it
Geometric Transformations
–Translation
–Scaling
–Rotation
–Reflection
–Shearing
85 3D Geometric Translation

Translation is defined as the displacement of any object by a


given distance and direction from its original position
86 3D Geometric Translation
 To translate a point in three dimensions by tx, ty and tz simply
calculate the new points as follows:
x’ = x + tx y’ = y + ty z’ = z + tz

(x, y, z)
(x’, y’, z’)
Translated Position
87 3D Geometric Translation
 The translation of a point P(x,y,z) by (tx, ty, tz) can be
written in matrix form as:

P Tv ( P ) where v tx I  ty J  tz K

1 0 0 tx   x  x
0  y
1 0 ty   y
T v  P   '  P  
0 0 1 tz  z  z
     
0 0 0 1 1  1 
Geometric Transformations

–Translation
–Scaling
–Rotation
–Reflection
–Shearing
89 3D Geometric Scaling
Scaling is the process of expanding or compressing the
dimensions of an object determined by the scaling factor.
90 3D Geometric Scaling
 To scale a point in three dimensions by sx, sy and sz simply
calculate the new points as follows:
x’ = sx*x y’ = sy*y z’ = sz*z

(x, y, z) (x’, y’, z’)

Scaled Position
91 3D Geometric Scaling
 The scaling of a point P(x,y,z) by scaling factors Sx, Sy and
Sz about origin can be written in matrix form as:
P Ssx, sy, sz( P ) where
 sx 0 0 0  x  x
 0 sy 0  y
0  y
Ssx, sy, sz  P   '  P  
 0 0 sz 0 z  z
     
0 0 0 1 1  1 
 x  sx 0 0 0  x   sx x 
 y 
0 sy 0 0  y   sy y 
such that  '    
z  0 0 sz 0  z   sz z 
       
1   0 0 0 1  1  1 
Geometric Transformations
–Translation
–Scaling
–Rotation
–Reflection
–Shearing
93 3D Geometric Rotations
 When we performed rotations in two dimensions we only
had the choice of rotating about the z axis
 In the case of three dimensions we have more options
 Rotate about x – pitch
 Rotate about y – yaw
 Rotate about z - roll
3D Geometric Rotations
94
 Roll is known as the rising or dipping of the airplane's wing. The movement is done
about Longitudinal axis. The Ailerons controlling the roll are located on the trailing
edge of both wings.
 Pitch refers to the movement of the airplane's nose either up or down. It movement is
done about Lateral axis. The elevator controls the pitch is also located on the rear of
the aircraft on the tail, along with the rudder.
 Yaw allows the airplane to move towards the left or right while in flight. The
movement is done about a ventricle axis. The yaw is controlled by the rudder located
in the rear of the aircraft on the tail.

Roll Pitch Yaw


95 3D Geometric Rotations
 Rotate about z – axis: The picture shows a z-axis rotation
around the origin in a positive angle, (Anti-clockwise) as you
look down the z-axis towards the origin. The angle is
measured in the xy-plane from the x-axis, just as in 2D.
96 3D Geometric Rotations
 Rotate about y – axis: You are looking down the y-axis
which is not shown. A positive (counter-clockwise) angle is
shown.
97 3D Geometric Rotations
 Rotate about x – axis: You are looking down the x-axis
which is not shown. A positive (counter-clockwise) angle is
shown.
98 3D Geometric Rotations
 The equations for the three kinds of rotations in 3-D are

x’ = x·cosθ - y·sinθ x’ = x x’ = z·sinθ + x·cosθ


y’ = x·sinθ + y·cosθ y’ = y·cosθ - z·sinθ y’ = y
z’ = z z’ = y·sinθ + z·cosθ z’ = z·cosθ - x·sinθ
3D Geometric Rotations
99

 The scaling of a point P(x,y,z) by an angle of  about


different axis about origin can be written in matrix form as:
P R , axis( P )
 x  x  cos   sin  0 0
 y  y  sin  cos  0 0
where P  '  P   R , K  
z  z  0 0 1 0
     
1
  1   0 0 0 1
 cos  0 sin  0 1 0 0 0
 0 1 0 0   0 cos   sin  0
R , J    R , I  
  sin  0 cos  0  0 sin  cos  0
   
 0 0 0 1  0 0 0 1
Geometric Transformations
–Translation
–Scaling
–Rotation
–Reflection
–Shearing
101 3D Geometric Reflections
 We can perform reflections relative to a selected reflection
axis or with respect to a reflection plane.
 Reflections relative to a given axis are equivalent to 180°
rotations about that axis.
 Reflections with respect to a plane are equivalent to 180°
rotations in 4D space.
 3 standard Reflections are
 About z axis or with respect to xy plane
 About y axis or with respect to zx plane
 About x axis or with respect to yz plane
3D Geometric Reflections
102

 Reflection about XY – plane: Reflection relative to the xy


plane can be obtained from following set of equations:
x’ = x y’ = y z’ = – z
 In homogenous matrix form
1 0 0
0
0 1 0 0
P' = Mxy(P) where M xy 
0 0  1 0
 
0 0 0 1

 Reflections about other planes can also be obtained by


symmetry.
103 3D Geometric Reflections
 Reflection about XY – plane is a useful reflection as it
converts a right-handed coordinate system into a left-handed
coordinate system.
y
y

x
x
z
104 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
Inverse Transformations
105

1
 Inverse Translation: Tv T v
1
 Inverse Scaling: S sx,sy,sz S1/ sx,1/ sy,1/ sz

1
 Inverse Rotations: R , p R  , p
1
M plane M plane
 Inverse Reflections:
106 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Combining transformations
3D Coordinate Transformations
107

 Coordinate Transformation: The object is held stationary


while coordinate system is moved relative to the object.
These can easily be described in terms of the opposite
operation performed by Geometric transformation.
3D Coordinate Transformations
110

 Coordinate Translation: 1
T v Tv T v
1
 Coordinate Scaling: S sx,sy,sz S sx,sy,sz S1/ sx,1/ sy,1/ sz
1
 Coordinate Rotations: R , p R , p R  , p

1
M plane M M plane
 Coordinate Reflections: plane
111 Contents

1. 3D Coordinate System
2. Vector Fundamentals
3. 3D Homogeneous Coordinate
4. 3D Geometric Transformations
5. 3D Inverse Transformations
6. 3D Coordinate Transformations
7. Composite transformations
113 Composite Transformation

 Various composite transformations are

1. Scaling about arbitrary point P


2. Tilting as rotation about x-axis followed by y-axis
3. Aligning vector V with K (Z – axis)
4. Rotation about arbitrary axis L
5. Mirror Reflection about arbitrary plane (N, R0)
114 Exercise 1

Scaling about arbitrary point P


 Imagine scaling an object around a point (a,b,c) other than the origin
 Translate point (a,b,c) to origin
 Scale around origin
 Translate back to point
115 Exercise 1
116 Exercise 1
Let P is the object point which is to be scaled by factors sx, sy and sz about the fixed
point (a,b,c). Then the composite transformation S sx,sy,sz,(a,b,c) can be obtained by
performing following sequence of transformations :
1. Translate (a,b,c) to origin and the new object point is found as
P1 = TV(P) where V= – aI – bJ– cK
2. Scale object about origin and the new object point is
P2 = Ssx,sy,sz(P1)
3. Retranslate (a,b,c) back the final object point is
PF = T-1V(P2) = T-V (P2)
The composite transformation can be obtained by back substituting
PF = T-1V(P2)
= T-V Ssx,sy,sz(P1)
= T-V Ssx,sy.TV(P) where V= – aI – bJ– cK
117 Exercise 1
Thus we form the matrix to be Ssx,sy,sz(a,b,c)= T-VSsx,sy,szTV
And the composite scaling transformation matrix is

1 0 0 a   sx 0 0 0  1 0 0  a
0 1 0 b   0 sy 0 0  0 1 0  b 
S sx, sy, sz ( a ,b ,c )   
0 0 1 c   0 0 sz 0  0 0 1  c
     
0 0 0 1   0 0 0 1  0 0 0 1
 sx 0 0  a.sx  a 
 0 sy 0  b.sy  b 

0 0 sz  c.sz  c 
 
0 0 0 1 
118 Exercise 2

Define tilting as rotation about the x-axis followed by a rotation


about y-axis.

a) Find the tilting matrix T = Ry,J x Rx,I


b) Does order of rotation matters ?
119 Exercise 3
Z axis
Aligning vector V with Vector K
Let V = aI+bJ+cK then the alignment can be
performed by following sequence of
operations:

•Rotate V about X-axis by an angle of 1, so P(a,b,c)


c
that V rotates into upper -half of the xz – V
plane. V’= R1,I(V)
a b
Y axis
•Rotate V’ about Y-axis by an angle of -2,
so that V’ rotates and align with Z – axis.
V”= R -2,J(V ’).
X axis
How to get these two angles???
120 Exercise 3
Z axis

Step1: Rotate V about X-axis by an angle of


1, so that V rotates into upper -half of the xz
V’
– plane. V’= R1,I(V) C P’(0,b,c)
Q(a,0,b2+c2
P(a,b,c)
Let P’ be projection of P(a,b,c) in YZ plane. V
1
P’↔(0,b,c). If 1 be the angle that OP
makes with +ve Z-axis, then from OP’C O B
b Y axis
sin 1  A
b2  c2
c
cos 1 
b2  c2 X axis
121 Exercise 3
Rotate vector V about X-axis by an angle of 1

V’= R1,I(V) or Q = R (P)


1,I

Where
1 0 0 0
 0 cos   sin 1 0
R1 , I  1

 0 sin 1 cos 1 0
 
0 0 0 1
b
sin 1 
b2  c2
c
cos 1 
b2  c2

Does V have rotated into upper -half of the xz – plane?


122 Exercise 3
1 0 0 0  a 
 0 cos   sin  0  b 
Q R1 , I ( P )  1 1  
 0 sin 1 cos 1 0  c 
  
 0 0 0 1   1
1 0 0 0  a 
 c b   a  cb  bc 
 0  0   b  
b 2
 c 2
b 2
 c 2
 .   b2  c2 
 b c b2  c2 
0 0  c  
 b2  c2 b2  c2   1  b2  c2 
0 0 0 1    1 
   
 a 
 0 
 2 2 
 b c 
 
 1 
123 Exercise 3
Z axis

R(0,0,a2+b2+c2)
Step2: Rotate V’ about Y-axis by an angle of
Q’(0,0,b2+c2)
– 2 , so that V’ aligns with +ve Z axis. V”=
V’
R ,I(V) a P’(0,b,c)
1
Q(a,0,b2+c2) C P(a,b,c)
Let Q’ be projection of Q(a,0,b2+c2) on Z 2 V
axis, Q’↔(0,0, b2+c2 ). If 2 be the angle
that OQ’ makes with +ve Z-axis, then from
O B
OQQ’ a Y axis
sin  2  A
a2  b2  c2
b2  c2
cos  2  X axis
a2  b2  c2
124 Exercise 3

Rotate vector V’ about Y-axis by an angle of – 2

V”= R-2,J(V’) or R = R- (Q)


2,J
 cos 1 0  sin  2 0
Where  0 1 0 0
R  2 , J 
 sin  2 0 cos  2 0
 
 0 0 0 1
a
sin  2 
a2  b2  c2
b2  c2
cos  2 
a2  b2  c2

Does V have aligned Z axis?


125 Exercise 3
 cos  2 0  sin  2 0  a 
 0 1 0 0  0 
R R  2 , J (Q)  
 sin  2 0 cos  2 0  b  c 
2 2

  
 0 0 0 1  1 
 b2  c2 a 
 2 0  0  a 
 a  b2  c2 a2  b2  c2  
0
 0 1 0 0 .
  b c 
2 2

a b2  c2
 0 0  
 a2  b2  c2 a2  b2  c2  1 
 0 0 0 1
 a b2  c2  a b2  c2 
 2 2 2
  0 
 a b c   
0
 0   
 2
a b c 2 2
  a b c 
2 2 2

 2 2 2
  
 a  b  c   1 
 1 
Exercise 3
126

Composite Matrix AV,K can be found as


R R  2 , J (Q) R  2 , J * R1 , I ( P) 
 b2  c2 a  1 0 0 0
 2 0  0  c b 
 a  b2  c2 a 2  b2  c2  0 2 2
 0
b c b2  c2
 0 1 0 0 .
 b c

a b  c2
2
0
 0 0  0 
 a2  b2  c2 a 2  b2  c2  b2  c2 b2  c2
 0 0 0 1  0 0 0 1

  ab ac 
 a  V  0
V 0  0  1 0 0 0 V V
V  c b   
  0  0  0 c b
  0   b2  c2
 a0 1 0

0 .
 b c      where
 0 
0 0 0  a b c  V  a 2  b2  c2
V V      0
 0
 0 0 1  0 0 0 1 V V V 
 0 0 0 1
Exercise 3
127

Corollary I: If both b = c =0
then  0, V  a and  2 900
 a 
0 0  0
a
 
AV , K  a0 1 0 0 .
 0 0 0
a 
0 0 0 1

R  2 , J
Exercise 3
128

Corollary II: The inverse of AV,K can be found as

A 1V , K ( R  2 , J . R1 , I )  1
1 1
R 1 , I .R  2 ,J
T T
R 1 , I .R  2 ,J
T
( R  2 , J . R1 , I )
T
( AV , K )
T
A V ,K
Exercise 4
129
Find transformation AV,N that aligns vector V = 2I – J – K with
another N = I+J+K.

 2 2   2 1 1 
 0 0    0
 6 6   3 2 3 2 3 
 2 1 1  1 1
  0 AK ,N  0  0
AV ,K  2 6 2 6  2 2 
 2   1 1 1 
1 1  0
  0
 2 6 2 6   3 3 3 
 0 0 0 1  0 0 0 1
 4 1 1 
 0
18 18 18
 
 1 2 1 2 1
    0
AV ,N  18 18 2 18 2 
 1 2 1 2 1 
     0
 18 18 2 18 2 
 0 0 0 1
130 Exercise 5

Rotation by an angle  about arbitrary axis L specified by a


direction vector V and fixed point P0.
The transformation can be found as:
1. Translate P0 to origin.
2. Align Vector V with K.
3. Rotate object about Z axis by angle .
4. Realign vector V back.
5. Retranslate P0 back.
131 Exercise 5
If P is the object point the sequence of transformations is:
1. Translate P0 to origin  P1 = T-P0(P)

2. Align Vector V with K.  P2 = AV,K(P1)


3. Rotate object about Z axis by angle .  P3 = R,K(P2)
4. Realign vector V back.  P4 = A-1V,K(P3)
5. Retranslate P0 back.  P5 = T-1-P0(P4)

Thus P5 = T-1-P0(P4)

= T-1-P0.A-1V,K(P3)

= T-1-P0.A-1V,K. R,K(P2)

= T-1-P0.A-1V,K. R,K. AV,K(P1)

= T-1-P0.A-1V,K. R,K. AV,K. T-P0(P)

Thus we form the matrix to be R,L= T-1-P A-1V,K R,K AV,KT-P


0 0
132 Exercise 5
Exercise 6
133

The pyramid is defined by A(0,0,0), B(1,0,0), C(0,1,0) and D(0,0,1) is


rotated by 450 about line L in the direction of V = J+K passing
through P(0,1,0). Find the coordinates of rotated figure.

 2 1 1 1   1 1 2 
    0 1 
 2 2 2 2   2 2 
 1 2 2 2 2 2 2
 2  2 2 4 2
1
2 2
R450 , L
 1
4 4 4   A' B' C ' D'  4 4 2 
2 2 2 2 2 2  2 2
  2 4 2 
 2 4 4 4   0 
 0 0 0 1   4 4 2 
 1 1 1 1 
134

Thank you!

You might also like