Notes 456 2D Transformations2 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

1/3/2023

EI-OE-401 Open Elective IV


(Computer Graphics and CAD/CAM)
Module - 2
2-D Viewing and Transformations

Prof. Pardeep Kumar


Department of Instrumentation,
Kurukshetra University, Kurukshetra-136119
pardeepk@kuk.ac.in

Module - II Syllabus
• Points and lines, Line drawing algorithms, midpoint circle and ellipse
algorithms. Filled area primitives: scan line polygon fill algorithm, boundary-
fill and flood fill algorithms.
• Translation, scaling, rotation, reflection and shear transformations, matrix
representations and homogeneous coordinates, composite transforms,
transformation between coordinate systems. 2-D Viewing: The viewing
pipeline, viewing coordinate reference frame, window to viewport coordinate
transformation, viewing functions, Cohen-Sutherland and Cyrus beck line
clipping algorithms After
completion
• Reference Books: there will be a
There will be
continuous
Computer Graphics by Hearn & Donald, PHI class test
evaluation in the
Computer Graphic by Plastock, McGraw Hill form of
Assignments,
Principle of Interactive graphics by Newman.W Spraul R.F., McGraw Hill
quizzes etc.
Procedural Elements of computer graphics by Rogers D.F., McGraw Hill

January 3, 2023 DOI, Kurukshetra University 2

1
1/3/2023

Two Dimensional
Viewing
January 3, 2023 DOI, Kurukshetra University 3

Two Dimensional Viewing


• Two Dimensional Viewing
– User controls contents, structure, and appearance of objects
and their displayed images via rapid visual feedback.

January 3, 2023 DOI, Kurukshetra University 4

2
1/3/2023

Model…..
• Model: a pattern, plan, representation, or description
designed to show the structure or working of an object,
system, or concept.
• Modeling: is the process of creating, storing and
manipulating a model of an object or a system

January 3, 2023 DOI, Kurukshetra University 5

Modeling…..
• In Modeling, we often use a geometric model
– i.e.. A description of an object that provides a
numerical description of its shape, size and various
other properties.
• Dimension of the object are usually given in units
appropriate to the object:
– meters for a ship
– kilometres for a country

January 3, 2023 DOI, Kurukshetra University 6

3
1/3/2023

Modeling
• The shape of the object is often described in terms of
sub-parts, such as circles, lines, polygons, or cubes.
• Example: Model of a house units are in meters
y

0,0 x

January 3, 2023 DOI, Kurukshetra University 7

Instances of Objects
• Instances of this object may then be placed in various
positions in a scene, or world, scaled to different sizes,
rotated, or deformed.
• Each house is created with instances of the same
model, ybut with different parameters.
9

0,0 x
January 3, 2023 DOI, Kurukshetra University 8

4
1/3/2023

2D Viewing

January 3, 2023 DOI, Kurukshetra University 9

2D Viewing
• Viewing is the process of drawing a view of a
model on a 2-dimensional display.
– The geometric description of the object or scene
provided by the model, is converted into a set of
graphical primitives, which are displayed where desired
on a 2D display.
– The same abstract model may be viewed in many
different ways:
• e.g. faraway, near, looking down, looking up
January 3, 2023 DOI, Kurukshetra University 10

5
1/3/2023

Real World Coordinates


• It is logical to use dimensions which are appropriate to the object
e.g.
– meters for buildings
– nanometers or microns for molecules, cells, atoms
– light years for astronomy

• The objects are described with respect to their actual physical


size in the real world, and then mapped onto screen co-
ordinates.
• It is therefore possible to view an object at various sizes by
zooming in and out, without actually having to change the
model.

January 3, 2023 DOI, Kurukshetra University 11

2D Viewing
• How much of the model should be drawn?
• Where should it appear on the display?
How do we convert Real-world coordinates into
screen co-ordinates?
– We could have a model of a whole room, full of objects such as
chairs, tablets and students.
– We may want to view the whole room in one go, or zoom in on
one single object in the room.
– We may want to display the object or scene on the full screen, or
we may only want to display it on a portion of the screen.

January 3, 2023 DOI, Kurukshetra University 12

6
1/3/2023

2D Viewing
• Once a model has been constructed, the programmer
can specify a view.
A 2-Dimensional view consists of two rectangles:
– A Window, given in real-world co-ordinates, which
defines the portion of the model that is to be drawn
– A Viewport given in screen co-ordinates, which
defines the portion of the screen on which the contents
of the window will be displayed

January 3, 2023 DOI, Kurukshetra University 13

Basic Interactive Programming


• Window: - What is to be viewed?
• Viewport: - Where is to be displayed?

Viewport

Image
Scene
January 3, 2023 DOI, Kurukshetra University 14

7
1/3/2023

Coordinate
Representations

January 3, 2023 DOI, Kurukshetra University 15

Coordinate Representations
• General graphics packages are designed to be used with
Cartesian coordinate specifications.
• Several different Cartesian reference frame are used to
construct and display a scene.
• Modeling coordinates: We can
construct the shape of individual
objects in a scene within separate
coordinate reference frames called
modeling (local) coordinates.
January 3, 2023 DOI, Kurukshetra University 16

8
1/3/2023

Coordinate Representations
• World coordinates: Once individual object shapes have been
specified, we can place the objects into appropriate positions
within the scene using reference frame called world coordinate.

Device Coordinates:
Finally, the world coordinates
description of the scene is
transferred to one or more
output-device reference
frames for display, called
device (screen) coordinates.

January 3, 2023 DOI, Kurukshetra University 17

Coordinate Representations
• Modeling coordinates: We can construct the shape of
individual objects in a scene within separate coordinate
reference frames called modeling (local) coordinates.

( xmax , ymax )

January 3, 2023 DOI, Kurukshetra University 18

9
1/3/2023

Coordinate Representations
• An initial modeling coordinate position is transferred to a
device coordinate position with the sequence:
(𝑥𝑚𝑐 , 𝑦𝑚𝑐 ) → (𝑥𝑤𝑐 , 𝑦𝑤𝑐 ) → (𝑥𝑛𝑐 , 𝑦𝑛𝑐 ) → (𝑥𝑑𝑐 , 𝑦𝑑𝑐 )
– The modeling and world coordinate positions in this
transformation can be any floating values;
– normalized coordinates satisfy the inequalities:
0 ≤ 𝑥𝑛𝑐 ≤ 1 0 ≤ 𝑦𝑛𝑐 ≤ 1
– The device coordinates are integers within the range (0,0) to
(𝑥𝑚𝑎𝑥 , 𝑦𝑚𝑎𝑥 ) for a particular output device.
January 3, 2023 DOI, Kurukshetra University 19

The Viewing
Pipeline
January 3, 2023 DOI, Kurukshetra University 20

10
1/3/2023

The Viewing Pipeline


• A world coordinate area selected for display is called
window.
• An area on a display device to which a window is
mapped; is a viewport.
• Windows and viewports are rectangular in standard
position.

January 3, 2023 DOI, Kurukshetra University 21

The Viewing Pipeline


• The mapping of a part of a world coordinate scene to device
coordinate is referred to as viewing transformation or
window-to-viewport transformation or windowing
transformation.

Viewport

window-to-viewport transformation
January 3, 2023 DOI, Kurukshetra University 22

11
1/3/2023

The Viewing Pipeline


1. Construct the scene in world coordinate using the output primitives.
2. Obtain a particular orientation for the window by setting up a two
dimensional viewing coordinate system in the world coordinate,
and define a window in the viewing coordinate system.

Transform descriptions in world coordinates to viewing coordinates (clipping).


January 3, 2023 DOI, Kurukshetra University 23

The Viewing Pipeline


3. Define a viewport in normalized coordinate, and map the viewing
coordinate description of the scene to normalized coordinate
4. (All parts lie outside the viewport are clipped), and contents of the
viewport are transferred to device coordinates.

1
Viewing Coordinate Normalized Coordinate Device Coordinate
January 3, 2023 DOI, Kurukshetra University 24

12
1/3/2023

The Viewing Pipeline

January 3, 2023 DOI, Kurukshetra University 25

The Viewing Pipeline


• By Changing the position of the viewport, we can view objects at
different position on the display area of an output device.

Viewport

January 3, 2023 DOI, Kurukshetra University 26

13
1/3/2023

The Viewing Pipeline


• By varying the size of viewport, we can change the size of displayed
objects (zooming).

Viewport

January 3, 2023 DOI, Kurukshetra University 27

2D Geometric
Transformations

January 3, 2023 DOI, Kurukshetra University 28

14
1/3/2023

2D Geometric Transformations
• Operations that are applied to the geometric description of an
object to change its position, orientation or size.
• Basic Transformation:

Translation

Rotation

Scaling

January 3, 2023 DOI, Kurukshetra University 29

2D Translation
• 2D Translation: Move a point along a straight-line path
to its new location.
y
x = x + t x , y  = y + t y

 x   x  t x 
 y =  y  + t 
P’

P      y
x
P = P + T
January 3, 2023 DOI, Kurukshetra University 30

15
1/3/2023

2D Translation
• Rigid-body translation: moves objects without deformation
(every point of the object is translated by the same amount)

Y 6

5 4
4
 
4

tx = 2 3

ty = 3 2
2
1 1 
 
0
1 2 3 4 5 6 7 8 9 10
X

Note: House shifts position relative to origin

January 3, 2023 DOI, Kurukshetra University 31

2D Rotation
• 2D Rotation: Rotate the points a specified rotation angle about
the rotation axis.

• Axis is perpendicular to xy plane; specify only rotation point


(pivot point (𝒙𝒓 , 𝒚𝒓 ))


yr
xr
January 3, 2023 DOI, Kurukshetra University 32

16
1/3/2023

2D Rotation
• Simplify: rotate around origin: 𝑥𝑟 = 0, 𝑦𝑟 = 0
𝑥 ′ = 𝑟 cos 𝜙 + 𝜃 = 𝑟 cos𝜙 cos𝜃 − 𝑟 sin𝜙 sin𝜃
𝑦 ′ = 𝑟 sin 𝜙 + 𝜃 = 𝑟 cos𝜙 sin𝜃 + 𝑟 sin𝜙 cos𝜃
𝑥 = 𝑟 cos𝜙, 𝑦 = 𝑟 sin𝜙

𝑥 ′ = 𝑥 cos𝜃 − 𝑦 sin𝜃
( x' , y ' ) 𝑦 ′ = 𝑥 sin𝜃 + 𝑦 cos𝜃

cos θ − sin θ 
r
( x, y ) R= 
 r
 sin θ cos θ 
 𝐏′ = 𝐑 ⋅ 𝐏
January 3, 2023 DOI, Kurukshetra University 33

2D Rotation
• Rotation of a point about an
arbitrary pivot position:

x = xr + ( x − xr ) cos  − ( y − yr ) sin 
y = yr + ( x − xr ) sin  + ( y − yr ) cos 

• The matrix expression could be


modified to include pivot coordinates
by matrix addition of a column vector
whose elements contain the additive
(translational) term.
January 3, 2023 DOI, Kurukshetra University 34

17
1/3/2023

2D Rotation
• Rigid-body translation: Rotates objects without deformation
(every point of the object is rotated through the same angle).

Y

6

5 =
6
4

1 

0
1 2 3 4 5 6 7 8 9 10
X

January 3, 2023 DOI, Kurukshetra University 35

2D Scaling
• 2D Scaling: Alters the size of an object.
• This operation can be carried out for polygons by
multiplying the coordinate values (𝑥, 𝑦) of each vertex by
scaling factors 𝑆𝑥 and 𝑆𝑦 to produce the transformed
coordinates

y sx = 2 y
sy = 1

x x

January 3, 2023 DOI, Kurukshetra University 36

18
1/3/2023

2D Scaling
𝑥 ′ = 𝑥 ⋅ 𝑆𝑥 , 𝑦 ′ = 𝑦 ⋅ 𝑆𝑦

𝑥′ 𝑆𝑥 0 𝑥
= ⋅
𝑦′ 0 𝑆𝑦 𝑦
P′ = S ⋅ P
y sx = 2 y
sy = 1

x x

January 3, 2023 DOI, Kurukshetra University 37

2D Scaling
• A positive numeric values can be assigned to the scaling
factors.
– Values less than 1 reduce the size of objects, and
– greater than 1 produce an enlargement.
• Uniform Scaling: 𝑺𝒙 = 𝑺𝒚
• Differential Scaling: 𝑺𝒙 ≠ 𝑺𝒚 , used in modeling applications.

s =s
x y s s
x y
original Uniform scaling Differential scaling
January 3, 2023 DOI, Kurukshetra University 38

19
1/3/2023

2D Scaling

Scale an object moving


its origin (upper right)

January 3, 2023 DOI, Kurukshetra University 39

2D Scaling
• We can control the location of a scaled object by choosing a position,
called fixes point (𝒙𝒇 , 𝒚𝒇 )
• Fixes point can be chosen as one of the vertices, the object
centroid, or any other position
x ' = x f + ( x − x f )  sx
y' = y f + ( y − y f )  sy

x ' = x  s x + x f (1 − s x )
y ' = y  s y + y f (1 − s y )

January 3, 2023 DOI, Kurukshetra University 40

20
1/3/2023

2D Scaling
x ' = x  s x + x f (1 − s x )
y ' = y  s y + y f (1 − s y )
• The matrix expression could be modified to include fixed coordinates.

Y 6

5
sx = 3 4

sy = 2 3

2
6  9 
1 2 3 2 2
1  1    
   
0
1 2 3 4 5 6 7 8 9 10
X
Note: House shifts position relative to origin

January 3, 2023 DOI, Kurukshetra University 41

2D Scaling
x ' = x  s x + x f (1 − s x )
y ' = y  s y + y f (1 − s y )
• The matrix expression could be modified to include fixed coordinates.
Y 6

5
sx = 3 4

sy = 2 3

2
6  9 
1 2 3 2 2
1  1    
   
0
1 2 3 4 5 6 7 8 9 10
X
Note: House shifts position relative to origin

January 3, 2023 DOI, Kurukshetra University 42

21
1/3/2023

Any Question?

Thanks!

January 3, 2023 DOI, Kurukshetra University 43

22

You might also like