0% found this document useful (0 votes)
10 views30 pages

M3 Transformations

The document provides an introduction to computer graphics, focusing on 2D transformations such as translation, rotation, and scaling, along with their applications in object construction. It also discusses the definitions of 2D objects, including lines, polygons, and circles, and extends to 3D object definitions and transformations. Key concepts from linear algebra, such as matrix notation and homogeneous coordinates, are introduced to facilitate the understanding of transformations in graphics.

Uploaded by

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

M3 Transformations

The document provides an introduction to computer graphics, focusing on 2D transformations such as translation, rotation, and scaling, along with their applications in object construction. It also discusses the definitions of 2D objects, including lines, polygons, and circles, and extends to 3D object definitions and transformations. Key concepts from linear algebra, such as matrix notation and homogeneous coordinates, are introduced to facilitate the understanding of transformations in graphics.

Uploaded by

RaraRahmadanic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

INTRODUCTION TO COMPUTER GRAPHIC S

Transformations

Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

What is 2D Transformation
in Computer Graphics?
• Transformation means a change in the object's
orientation, size, and shape. They position the object,
change its shape, and even change how something is
viewed.
• Transformation plays a major role in computer
graphics, repositioning the graphics on the screen and
changing their size or orientation.
• The basic geometrical 2D Transformation
in Computer Graphics are:
• Translation
• Rotation
• Scaling
• The derivedStuff
geometrical transformation is:
• Reflection
• Shearing
INTRODUCTION TO COMPUTER GRAPHIC S

How Are Geometric


Transformations (T,R,S) Used
in Computer Graphics?
• Object construction using
assemblies/hierarchy of parts

“is composed of hierarchy”

ROBOT transformation

upper body lower body

stanchion base

head trunk arm

Stuff Scenegraph
(see Sceneview assignment)
INTRODUCTION TO COMPUTER GRAPHIC S

2D Object Definition (1/3)


Lines and Polylines
• Polylines: lines drawn between ordered points

• Same first and last point make closed polyline


or polygon
• If it does not intersect itself, called simple
polygon

Convex vs. Concave Polygons

Convex: For every pair of


points in the polygon, the
line between them is fully
contained in the polygon.
Stuff
Concave: Not convex: some
two points in the polygon are
joined by a line not fully
contained in the polygon.
INTRODUCTION TO COMPUTER GRAPHIC S

2D Object Definition (2/3)


Special polygons

triangle square

rectangle
Circles
• Consist of all points equidistant from one
predetermined point (the center)
• (radius) r = c, where c is a constant
P1
r y
r
StuffP0 0 x

• On a Cartesian grid with center of circle at


origin equation is r2 = x2 + y2
INTRODUCTION TO COMPUTER GRAPHIC S

2D Object Definition (3/3)


Circle as polygon
• Informally: a regular polygon with > 15 sides

(Aligned) Ellipses

A circle scaled along the x or y axis

6 6
5 5
4 4
3 3
2 2
1 1

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

Stuff
Example: height, on y-axis, remains 3, while length, on
x-axis, changes from 3 to 6
INTRODUCTION TO COMPUTER GRAPHIC S

2D to 3D Object Definition
Vertices in motion (“Generative object description”)
• Line is drawn by tracing path of a point as it
moves (one dimensional entity)

• Square drawn by tracing vertices of a line as it


moves perpendicularly to itself (two dimensional
entity)

• Cube drawn by tracing paths of vertices of a


square as it moves perpendicularly to itself
(three-dimensional entity)
Stuff
• Circle drawn by swinging a point at a fixed length
around a center point
INTRODUCTION TO COMPUTER GRAPHIC S

Building 3D Primitives

• Triangles and tri-meshes

• Often parametric polynomials, called splines

Curves Patches
Stuff
Boundaries are
Polynomial curves
In 3D
INTRODUCTION TO COMPUTER GRAPHIC S

Useful concepts from Linear


Algebra
You will need to understand these
concepts:
• 3D Coordinate geometry
• Vectors in 2 space and 3 space
• Dot product and cross product –
definitions and uses
• Vector and matrix notation and algebra
• Properties (associativity but NOT
commutativity)
• Matrix transpose and inverse – definition,
use, and calculation
• Homogeneous coordinates

Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

Short Linear Algebra


Digression: Vector and Matrix
Notation, A non-Geometric
Example (1/2)
Let’s Go Shopping
• Need 6 apples, 5 cans of soup, 1 box of
tissues, and 2 bags of chips

• Stores A, B, and C (East Side Market, Whole


Foods, and Store 24) have following unit prices
respectively

1 can of 1 box of 1 bag of


1 apple soup tissues chips
East Side $0.20 $0.93 $0.64 $1.20
Whole Foods $0.65 $0.95 $0.75 $1.40
Store 24
Stuff
$0.95 $1.10 $0.90 $3.50
INTRODUCTION TO COMPUTER GRAPHIC S

A Non-Geometric Example (2/2)

• Shorthand to representation of the situation


(assuming we can remember order of items and
corresponding prices):

6 
• Column vector for quantities, q:5 
1 
 
 2

• Row vector corresponding prices at stores (P):

store A (East Side) [0.20 0.93 0.64 1.20]


store B (Whole Foods) [0.65 0.95 0.75 1.40]

Stuff
store C (Store 24) [0.95 1.10 0.90 3.50]
INTRODUCTION TO COMPUTER GRAPHIC S

What do I pay?

Let’s calculate for each of the three stores.


• Store A:
4

totalCostA =  PAiqi
i=1

= (0.20 • 6) + (0.93. • 5) + (0.64 • 1) + (1.20 • 2)


= (1.2 + 4.65 + 0.64 + 2.40)
= 8.89

• Store B:
4

totalCostB =  PBiqi = 3.9 + 4.75 + 0.75 + 2.8 = 12.2


i=1

• Store C:
Stuff 4
totalCostC =  PCiqi = 5.7 + 5.5 + 0.9 + 7 = 19.1
i=1
INTRODUCTION TO COMPUTER GRAPHIC S

Using Matrix Notation

• Can express these sums more compactly:

6 
 totalCost A 0.20 0.93 0.64 1.20  
P( All ) = totalCost B  = 0.65 0.95 0.75 1.40   
5
1 
totalCost C  0.95 1.10 0.90 3.50  
 2

• Determine totalCost vector by row-column


multiplication
– dot product is the sum of the pairwise
multiplications
• Apply this operation to rows of prices and
column of quantities

Stuff x 
y 
a b c d    = ax + by + cz + dw
z 
 
 w
INTRODUCTION TO COMPUTER GRAPHIC S

2D Translation
Y 6
Note: House
5  4 shifts position
 4 relative to origin
 
4

dx = 2 3

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

• Component-wise addition of vectors


x   x'  dx 
v’ = v + t where v =  , v' =  , t =  
 y  y ' dy 
and x’ = x + dx
y’ = y + dy
Stuff
To move polygons: translate vertices (vectors) and
redraw lines between them
• Preserves lengths (isometric)
• Preserves angles (conformal)
INTRODUCTION TO COMPUTER GRAPHIC S

2D Scaling
Y 6
Note: House
5 shifts position
sx = 3 4
relative to origin

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

• Component-wise scalar multiplication of vectors


x   x' 
v’ = Sv where v =  , v' =  
 y  y '

sx 0  x' = s x x
and S= 

Stuff0 s y y' = s y y

• Does not preserve lengths


• Does not preserve angles (except when scaling is
uniform)
INTRODUCTION TO COMPUTER GRAPHIC S

2D Rotation
Y 6
 Note: House
5 =
6 shifts position
4
relative to origin
3

1 

0
1 2 3 4 5 6 7 8 9 10
X
NB: A rotation by 0 angle, i.e. no rotation at all, gives us the identity matrix

• Rotation of vectors through an angle 


x   x' 
v’ = Rq v where v =  , v' =  
 y  y '

and x’ = x cos Ө – y sin Ө cos  − sin  


Stuff R = 
y’ = x sin Ө + y cos Ө sin  cos  

• Preserves lengths and angles


INTRODUCTION TO COMPUTER GRAPHIC S

2D Rotation and Scale are


Relative to Origin
• Suppose object is not centered at origin
• Solution: move to the origin, scale and/or
rotate, then move it back.

Stuff
• Would like to compose successive
transformations…
INTRODUCTION TO COMPUTER GRAPHIC S

Homogenous Coordinates
• Translation, scaling and rotation are expressed
(non-homogeneously) as:

translation: v’ = v + t
scale: v’ = Sv
rotation: v’ = Rv

• Composition difficult to express


– translation not expressed as a matrix
multiplication
• Homogeneous coordinates/projective coordinates
allows expression of all three as 3x3 matrices for
easy composition
P2 d ( x, y ) → Ph ( wx , wy , w), w  0
Ph ( x' , y ' , w), w  0
 x' y ' 
Stuff2 d
P ( x , y ) = P2d  , 
w w

• w is 1 for affine transformations in graphics


INTRODUCTION TO COMPUTER GRAPHIC S

x 
What is y
  ?
 w
• P2d is intersection of line determined by Ph with
the w = 1 plane

Ph (x,y,w)

1
P2d (x/w,y/w,1)

Y
Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

Stuff

polynomial curve defined in homogeneous coordinates (blue)


and its projection on plane – rational curve (red)
INTRODUCTION TO COMPUTER GRAPHIC S

2D Homogeneous Coordinate
Transformations
• For points written in homogeneous coordinates,

x 
 y ,
 
1 

translation, scaling and rotation relative to the


origin are expressed homogeneously as:

Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

Matrix Compositions: Using


Translation
• Avoiding unwanted translation when scaling or
rotating an object not centered at origin:
– translate object to origin, perform scale or
rotate, translate back.

House ( H ) T (dx, dy) H R( )T (dx, dy) H T (−dx,−dy) R( )T (dx, dy) H

• How would you scale the house by 2 in “its” y and


rotate it through 90° ?
House ( H ) S (1,2) H R( / 2) S (1,2) H

Stuff
• Remember: matrix multiplication is not
commutative! Hence order matters!
INTRODUCTION TO COMPUTER GRAPHIC S

Transformations are NOT


Commutative
Y 6

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

Y 6

3
Stuff
2

0
1 2 3 4 5 6 7 8 9 10
X
Rotation → Translation
INTRODUCTION TO COMPUTER GRAPHIC S

3D Basic Transformations (1/2)


(right-handed coordinate system)
y

1 0 0 dx 
 1 0 dy 
• Translation 0
0 0 1 dz 
 
0 0 0 1

sx 0 0 0
Stuff  0 sy 0 0
• Scaling 0 0 sz 0
 
0 0 0 1
INTRODUCTION TO COMPUTER GRAPHIC S

3D Basic Transformations (2/2)


(right-handed coordinate system)
• Rotation about X-axis
1 0 0 0
0 cos  − sin  0

0 sin  cos  0
 
0 0 0 1

• Rotation about Y-axis


 cos  0 sin  0
 0 1 0 0

− sin  0 cos  0
 
 0 0 0 1

• RotationStuff
about Z-axis
cos  − sin  0 0
 sin  cos  0 0

 0 0 1 0
 
 0 0 0 1
INTRODUCTION TO COMPUTER GRAPHIC S

Skew/Shear/Translate (1/2)

• “Skew” a scene to the side:


 1 
1
Skew =  tan  
0 1 

• Squares become parallelograms - x coordinates
skew to right, y coordinates stay same
• 90° between axes becomes Ө
• Like pushing top of deck of cards to the side –
each card shifts relative to the one below
• Hmmm… Notice that the base of the house (at
y=1) remains horizontal, but shifts to the right…

Y 6

5

4 =
4
3

2
Stuff
1

0
1 2 3 4 5 6 7 8 9 10
X
NB: A skew of 0 angle, i.e. no skew at all, gives us the identity matrix, as it should
INTRODUCTION TO COMPUTER GRAPHIC S

Skew/Shear/Translate (2/2)

• Everything along line y=1 stays on line y=1, but


translated to the right
• Distance between points on line is preserved
• A 1D homogeneous coordinate translation looks like
2D skew transformation

 1  1 dx 
• 1 tan     
0   0 1 
 1 

original y-axis
1 1
T = 
0 1

Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

Transforms in Scene Graphs (1/3)

• 3D scenes are often stored in a directed acyclic


graph (DAG) called a scene graph
– Open Scene Graph (used in the Cave)
– Sun’s Java3D
– X3D (aka VRML )

• Typical scene graph format:


– objects (cubes, sphere, cone, polyhedra etc.)
– stored as nodes (default: unit size at origin)
– attributes (color, texture map, etc.) and
transformations are also nodes in scene graph
(labeled edges on slide 2 are an abstraction)

Stuff
INTRODUCTION TO COMPUTER GRAPHIC S

Transforms in Scene Graphs (2/3)

Closer look at Scenegraph from slide 2 …

5. To get final scene

ROBOT

4. Transform subgroups

3. To make sub-groups upper body lower body

2. We transform them

Stuff stanchion base

head trunk arm

1. Leaves of tree are standard size object primitives


INTRODUCTION TO COMPUTER GRAPHIC S

Cukup Sekian

Stuff

You might also like