cs 112 –transformations igraphics.ics.uci.edu/cs112/lectures/xform1.pdf · slide 21 linear...

37
Slide 1 CS 112 – Transformations I

Upload: others

Post on 18-Jan-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 1

CS 112 – Transformations I

Page 2: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 2

Geometric Entities

n Points – P = (x,y,z)n Vectors

n Two points : v = P-Qn (xP-xQ, yP-yQ,zP-zQ) = (vx, vy, vz)

n Magnitude - | v |n Sqrt((xP-xQ)2 + (yP-yQ) 2+ (zP-zQ)2)

n Direction n v = | v | v n v - Unit Vector

Q

P

v

v

Page 3: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 3

Vector Operations

n u (ux, uy, uz) and v (vx, vy, vz)n Addition

n (ux+vx, uy+vy, uz+vz)n Subtraction n Scaling

n Direction does not changen Linear dependency

n v = α1 v1 + α2 v2 + … αn vn

u

vu+v

2u+v

-v

u -v

2u

v

Page 4: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 4

Vector Operationsn Dot Products - scalar

n (uxvx + uyvy + uzvz) n Magnitude – Sqrt(u.u)n Angle between two vectors, Cos θ = u.v

|u||v|Hence zero for orthogonal vectors[vx vy vz]

= v.uuxuyuz

Page 5: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 5

Vector Operationsn Cross Product

n n = u x v n Orthogonal of plane of u and vn (uyvz – uzvy, uzvx – uxvz, uxvy – uyvx)

n sin θ = | u x v|| u | | v |

n Hence, zero for parallel vectors

u

v

n

Page 6: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 6

Lines

n Defined by a point and a vectorn L(α) = P + α(Q-P)n Parametric equationn L(α) = P + α(Q-P)

= αQ + (1-α)P= α1Q + α2P

where α1 + α2 = 1Line is an affine sum of two points

P

Q

α = 0

α = 1

α > 1

α < 0

Page 7: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 7

Convexity

n Affine sumn Points defined by affine sum lie on the line

between the two pointsn Generalized for n points

n L = α1 P1 + α2 P2 + …. αn Pn

where α1 + α2 + …. αn = 1, 0 ≤ ai ≤ 1Lies in the convex hull of the points

Page 8: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 8

Planesn Three non-collinear points define a planen S(α) = αP + (1-α)Qn T(β) = βS + (1-β)R = αβP + β(1-α)Q + (1-

β)Rn T(β) = P + β(1-α)(Q-P) + (1-β)(R-P)

n Defined by a point and two vectorsn n = (Q-P) x (R-P)

n n is the normal to the planen n.(T – P) = 0

PQ

R

S(α)

T(α,β)

Page 9: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 9

Homogeneous Coordinates

P (x,y)

X

Y

y=1

P’ (x/y,1) 1D points on the line is represented by 2D array,

called homogeneous coordinates

Q (2x,2y)

Any point on the same vector has the same

homogeneous coordinates

Note: (2x/y, 2), (3x/y,3), and (x/y,1) represent the same

1D point P’

Page 10: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 10

Generalize to Higher Dimensions

X

Y

Z

P’ (x/z, y/z, 1)

P (x, y, z)

2D points represented by homogeneous

coordinates

Similarly, 3D points are represented by homogeneous

coordinates

If (x,y,z,w) is the homogeneous coordinate of a 3D point, where w = 1,

then the 3D point is given by (x/w,y/w,z/w,1)

Page 11: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 11

Homogeneous Coordinates

n 4 array for describing 3D points and vectorsn Points

n Vectors = P2-P1 =

α1

α2

α3

1β1

β2

β3

0

Page 12: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 12

Coordinate Systemsn Represent a point as a linear combination of

three vectors and the originn Linearly independent vectors – basis

n Orthogonal vectors are linearly independentw = α1v1 + α2v2 + α3v3 + R

[ α1 α2 α3 1 ] = wv1

v2

v3

Rv1

v2

v3

w

α1

α2

α3

Page 13: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 13

Linear Combination

n Points

n Vectors

[ α1 α2 α3 1 ] v1

v2

v3

R

= α1v1 + α2v2 + α3v3 + R

[ β1 β2 β3 0 ] v1

v2

v3

R

= β1v1 + β2v2 + β3v3

Page 14: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 14

Generating Coordinate Systems

U

V

N = U x V

W = N x U

Page 15: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 15

Change of Coordinates

n First coordinate – v1, v2, v3, R1n Second coordinate – u1, u2, u3, R2

v1

v2

v3

R1

u1

u2

u3

R2

P α1

α2

α3

1

= C2

Page 16: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 16

Change of Coordinates

n First coordinate – v1, v2, v3, R1n Second coordinate – u1, u2, u3, R2

v2

u3

u1 = γ11v1 + γ12v2 + γ13v3

u2 = γ21v1 + γ22v2 + γ23v3

u3 = γ31v1 + γ32v2 + γ33v3

R2 = γ41v1 + γ42v2 + γ43v3 + R1

v1

v2

v3

R1

u1

u2

u3

R2

P

Page 17: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 17

Change of Coordinates

u1 = γ11v1 + γ12v2 + γ13v3

u2 = γ21v1 + γ22v2 + γ23v3

u3 = γ31v1 + γ32v2 + γ33v3

R2 = γ41v1 + γ42v2 + γ43v3 + R1

u1

u2

u3

R2

v1

v2

v3

R1

= M

γ11 γ12 γ13 0γ21 γ22 γ23 0γ31 γ32 γ33 0γ41 γ42 γ43 1

M =

Page 18: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 18

Change of Coordinates

If R1 = R 2,

then γ41 = γ42 = γ43 = 0

γ11 γ12 γ13 0γ21 γ22 γ23 0γ31 γ32 γ33 00 0 0 1

M =

Page 19: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 19

Change of Coordinates

P = C2T u1

u2

u3

R2

= C2T M v1

v2

v3

R1

= C1T v1

v2

v3

R1

Hence, C1T= C2

T M

Page 20: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 20

Linear Transformationn Transformation: Function that maps a point

(vector) to another point (vector) n q = T(p)

n Linear Transformationn T(ap+bq) = aT(p) + bT(q)n If transformation of vertices are known,

transformation of linear combination of vertices can be achieved

Page 21: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 21

Linear Transformation

n Preserves points, straight lines and planes.n Preserves zero points. n Sets of parallel lines remain parallel after a

linear transformation. n Does not necessarily preserve angles

between lines or distances between points, though it does preserve ratios of distances between points lying on a straight line.

n Scaling, rotation, shear.

Page 22: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 22

Linear Transformations

n All linear transformations can be represented using matrix multiplication of appropriate size.

n Consider a point P(x,y,z). A linear transformation of P is

a21 a22 a23

a31 a32 a33

a11 a12 a13 xyz

Page 23: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 23

Affine Transformation

n Linear Transformation + Translationn q = T(p) + r where T is a linear

transformation, and r is the translation.n All properties of linear transformation except

it need not preserve the zero point. n All linear transformations are affine. But not

all affine transformations are linear.n Translation, in addition to, scaling, rotation,

shear.

Page 24: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 24

Affine Transformations

n All affine transformations can be represented using matrix multiplication of appropriate size.

n Consider a point P(x,y,z). An affine transformation of P is

a21 a22 a23

a31 a32 a33

a11 a12 a13 xyz

+b1b2

b3

= a21 a22 a23 b2

a31 a32 a33 b3

a11 a12 a13 b1 xyz1

Page 25: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 25

Input-Output Format Consistencyn Input is a 4x1 vector. Output should be too.

So a 4x4 matrix is used instead of 3x4.

a21 a22 a23 b2

a31 a32 a33 b3

a11 a12 a13 b1 xyz10 0 0 1

X’Y’Z’1

=

Page 26: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 26

Matrix Transformationsn q = Tp

n p and q are points or vectors in 4x1 homogeneous coordinates

n T is a 4x4 square matrix (16 degrees of freedom)

α11 α12 α13 α14

T = α21 α22 α23 α24

α31 α32 α33 α34

α41 α42 α43 α44

Page 27: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 27

Matrix Transformationsn The last element of p and q is either 0 or 1

n 12 degrees of freedom n If dealing with vectors

n Last column does not have an effect (9 degrees of freedom)

α11 α12 α13 α14

T = α21 α22 α23 α24

α31 α32 α33 α34

0 0 0 1

Page 28: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 28

Matrix Transformationsn Can also be seen as

n Transforming vertices in the same coordinatesn Changing the underlying coordinate to change

the representation of the vertices

α11 α12 α13 α14

T = α21 α22 α23 α24

α31 α32 α33 α34

0 0 0 1

Page 29: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 29

Preservation of Lines

n L(α) =α1Q + α2Pn Apply transformation

n T (L(α)) =T(α1Q) + T(α2P)=α1T(Q) + α2T(P)

n Practical application of transformationsn Transforming end points of the lines is sufficient

n No need to transform all the points in the linen Pass vertices through graphics pipelinen Render the transformed line during rasterization

Page 30: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 30

Translationxyz1

P =

x’y’z’1

P’ =

x’ = x + txy’ = y + tyz’ = z + tz

P’ = TP

1 0 0 tx

T =

0 0 0 1

0 1 0 ty

0 0 1 tz

Denoted by T(tx, ty, tz)

Page 31: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 31

Translationxyz1

P =

x’y’z’1

P’ =

x = x’ - txy = y’ - tyz = z’ - tz

P = T-1P’

1 0 0 -tx

T-1 =

0 0 0 1

0 1 0 -ty

0 0 1 -tz

T-1 = T(-tx, -ty, -tz)

Page 32: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 32

Example translation

Page 33: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 33

Scalingxyz1

P =

x’y’z’1

P’ =

x’ = sx xy’ = sy yz’ = sz z

P’ = SP

sx 0 0 0

S =

0 0 0 1

0 sy 0 00 0 sz 0

Denoted by S(sx, sy, sz)

S-1 = S(1/sx, 1/sy, 1/sz)

Page 34: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 34

Rotation in 2Dx = ρ cos φ

(x,y)

φθ

(x’,y’)

ρ

y = ρ sin φ

x’ = ρ cos (θ + φ)y’ = ρ sin (θ + φ)

x’ = ρ cosθ cosφ - ρ sinθ sinφ = x cosθ – y sinθ

y’ = ρ sinθ cosφ + ρ cosθ sinφ = x sinθ + y cosθ

= RR = x’

y’xy

cosθ –sinθsinθ cosθ

Page 35: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 35

Rotation in 3D about z axis

x’ = x cosθ – y sinθy’ = x sinθ + y cosθz’ = z

cosθ –sinθ 0 0 sinθ cosθ 0 0

P’ = RzP

Rz =

0 0 0 1 0 0 1 0

0 cosθ –sinθ 0 0 sinθ cosθ 0

Rx =

0 0 0 1

1 0 0 0

Denoted by R(θ)

R-1 = R(-θ) = RT(θ)Where R = Rx or Ry or Rz

Page 36: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 36

Shear

n Translation of one coordinate of a point is proportional to the ‘value’ of the other coordinate of the same point.n Point : (x,y)n After ‘y-shear’: (x+ay,y)n After ‘x-shear’: (x,y+bx)

n Changes the shape of the object.

Page 37: CS 112 –Transformations Igraphics.ics.uci.edu/CS112/lectures/xform1.pdf · Slide 21 Linear Transformation n Preserves points, straight lines and planes. n Preserves zero points

Slide 37

Using matrix for Shear

n Example: Z-shear (Z coordinate does not change)

1 0 a 00 1 b 00 0 1 00 0 0 1

xyz1

=

x+azy+bz

z1

=

x’y’z’1