downstate medical center division of pediatric surgery

25
Computer Graphics Geometrical Transformations 2D (FvFH Ch5)

Upload: others

Post on 03-Feb-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Computer Graphics

Geometrical Transformations2D (FvFH Ch5)

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

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

p’ = A * p

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

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

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’)

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

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))

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)

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

Reflectionx’ = -x

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

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

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

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

• equivalent to rotating 180 degrees

Shearing• stretching in one direction while fixing one line

θ

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

θ

shx = tan(90 – θ)

= cot(θ)

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

θ

shy = tan(θ)

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

2D Translation

2D Scale

2D Rotation

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

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

clockwise

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

Example2. rotate the line about the origin by 30 degrees

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

30 degrees