computer graphics - gettysburg college

25
Computer Graphics Geometrical Transformations 2D (FvFH Ch5)

Upload: others

Post on 04-Feb-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Graphics - Gettysburg College

Computer Graphics

Geometrical Transformations2D (FvFH Ch5)

Page 2: Computer Graphics - Gettysburg College

Affine Transformation• rigid transformation: preserves relative distances and angles

– translation, rotation, reflection

• non-rigid transformation: scale, shear

• affine transformation:– informally, rigid and non-rigid transformations that keep the parallel lines

parallel– more formally, all transformation in the following format

p’ = A * p + bwhere A is a matrix, P’, P, and B vectors

– ex) translation, scale, rotation, reflection, shear

Page 3: Computer Graphics - Gettysburg College

Affine Transformation• matrix representation of a 2D affine transformation:

p’ = A * p

Page 4: Computer Graphics - Gettysburg College

Scaling• matrix representation of a 2D scaling by Sx, Sy:

• uniform scaling: Sx = Sy• non-uniform scaling: Sx != Sy

Page 5: Computer Graphics - Gettysburg College

Translation• move objects to new positions by (tx, ty)• tx: horizontal translation amount• ty: vertical translation amount• essentially, add (tx, ty) to all vertices of an object

P(x, y)

P’(x’, y’)

Page 6: Computer Graphics - Gettysburg College

Translation• matrix representation of a 2D translation by tx, ty:

Page 7: Computer Graphics - Gettysburg College

Rotation

p(x, y)

p’(x’, y’)

ab

R: radius

p(x, y) = (Rcos(a), Rsin(b))

p’(x’, y’) = (Rcos(a+b), Rcos(a+b))

Page 8: Computer Graphics - Gettysburg College

RotationRecall, sin(a + b) = sin(a)cos(b) + cos(a)sin(b)

cos(a + b) = cos(a)sin(b) – cos(b)sin(a)

p(x, y) = (Rcos(a), Rsin(a))p’(x’, y’) = (Rcos(a+b), Rsin(a+b))

x’ = Rcos(a+b) = R(cos(a)sin(b) – cos(b)sin(a)) = Rcos(a)sin(b) – Rcos(b)sin(a) x = Rcos(a), y = Rsin(a)= x*sin(b) – y*cos(b)

y’ = Rsin(a+b) = R(sin(a)cos(b) + cos(a)sin(b))= Rsin(a)cos(b) + Rcos(a)sin(b)= y*cos(a) + x*sin(b)= x*sin(b) + y*cos(a)

Page 9: Computer Graphics - Gettysburg College

Rotation• matrix representation of a 2D rotation by θ:

Page 10: Computer Graphics - Gettysburg College

Reflectionx’ = -x

x’ = -xy’ = -y y’ = -y

Page 11: Computer Graphics - Gettysburg College

Horizontal Reflection• matrix representation of a 2D horizontal reflection:

Page 12: Computer Graphics - Gettysburg College

Vertical Reflection• matrix representation of a 2D horizontal reflection:

Page 13: Computer Graphics - Gettysburg College

Reflection about y = x line• matrix representation of horizontal-vertical reflection:

• equivalent to rotating 180 degrees

Page 14: Computer Graphics - Gettysburg College

Shearing• stretching in one direction while fixing one line

θ

Page 15: Computer Graphics - Gettysburg College

Horizontal Shearing• matrix representation of a 2D horizontal reflection:

θ

shx = tan(90 – θ)

= cot(θ)

Page 16: Computer Graphics - Gettysburg College

Vertical Shearing• matrix representation of a 2D horizontal reflection:

θ

shy = tan(θ)

Page 17: Computer Graphics - Gettysburg College

Homogeneous Coordinates• notice that all transformations except for translation could be

expressed in the affine transformation format (p’ = A * p + b where b in all cases is (0, 0)T

• to also express translation as matrix * vector multiplication (instead of addition of two vectors), use homogeneous coordinates

• homogeneous coordinates: one additional coordinate W– can represent all 2D affine transformations with (3x3 matrix) * (3x1

vector) multiplication

Page 18: Computer Graphics - Gettysburg College

2D Translation

Page 19: Computer Graphics - Gettysburg College

2D Scale

Page 20: Computer Graphics - Gettysburg College

2D Rotation

Page 21: Computer Graphics - Gettysburg College

To Consider• Rotation/scaling of objects not anchored at the Origin

– translate the object to the origin– rotate or scale– translate the object back to where it was anchored before

Page 22: Computer Graphics - Gettysburg College

Example• Rotate the below line around the left endpoint by 30 degrees counter

clockwise

Page 23: Computer Graphics - Gettysburg College

Example1. translate the line to the origin (the left endpoint is at the origin)

Page 24: Computer Graphics - Gettysburg College

Example2. rotate the line about the origin by 30 degrees

Page 25: Computer Graphics - Gettysburg College

Example3. translate the line (left endpoint) to where it was before

30 degrees