320 likes | 424 Views
GEOMETRIC TRANSFORMATIONS. Review of Mathematical Preliminaries Points:. Vectors : directional lines. P 1 (x 1 ,y 1 ). P 0 (x 0 ,y 0 ). 1 . A vector has a direction and a length: Length: |V|=(x 2 + y 2 ) 1/2 A unit vector: |V| = 1 e.g.: Normalize a vector:
E N D
GEOMETRIC TRANSFORMATIONS Review of Mathematical Preliminaries Points: • Vectors: directional lines P1(x1,y1) P0(x0,y0)
1. A vector has a direction and a length: Length: |V|=(x2 + y2)1/2 A unit vector: |V| = 1 e.g.: • Normalize a vector: 2. Add two vectors • 3. Scalar Multiplication
V • W , • 4. Dot product of two vectors scalar • V W if = 90 => cos = 0 => V W = 0. • if < 90 => cos > 0 => V W > 0. • if > 90 => cos < 0 => V W < 0. • 5.Normal: a unit vector perpendicular to a surface
. • Lines y = mx+b e.g.: y = x; ax+by+c=0 Let f(x,y) = ax + by + c A point p(xp,yp) is on the line if f(xp,yp) = 0. When b < 0: p(xp,yp) is above the line if f(xp,yp) < 0. p(xp,yp) is below the line if f(xp,yp) > 0. When b > 0: p(xp,yp) is above the line if f(xp,yp) > 0. p(xp,yp) is below the line if f(xp,yp) < 0.
Parametric Form: P(t)=P0+t(P1-P0); 0 <= t <= 1 P1(x1,y1) P0(x0,y0) • P(t)=P0+t(P1-P0)
Where, • x(t) = x0 + t * (x1 – x0) • y(t) = y0 + t * (y1 – y0) • 0 <= t <= 1 • x(t) = (1-t) * x0 + t * x1 • y(t) = (1-t) * y0 + t * y1 • 0 <= t <= 1
2D Transformations • Translate a point The algebraic representation of translation of point P(x,y) by D(dx,dy) is x’= x + dx y’= y + dy Its “matrix” representation is • Its logical representation is P’ = P + D • Its visual representation is P’ (x’,y’) P(x,y) D(dx,dy)
Y Y 10 10 5 5 X X 0 0 5 5 10 10 (4,5) (7,5) (10,1) (7,1) Before Translation After Translation • To move a shape: translate every vertex of the shape
Scaling (relative to the origin) Scale a point P(x,y) by S(sx,sy) Algebraic: x’=sx* x y’=sy* y Matrix: Logic: P’ = SP or P’ = S(sx,sy)P Scale a line P0P1 (scale each point) P0’=SP0 • P1’=SP1
Y Y 10 10 5 5 X X 0 0 5 5 10 10 (4,5) (7,5) (2,5/4) (7/2,5/4) Before Scaling After Scaling • Scale a shape: scale every vertex of the shape. Visual representation Uniform Scaling:sx=sy
Rotate (around the origin) Positive angles are measured counterclockwise from x axis to y axis. • Rotate point (x,y) around the origin Algebraic representation: x’ = x * cos - y * sin y’ = x * sin + y * cos Matrix representation: Logic representation: P’ = RP
(4.9, 7.8) (2.1, 4.9) (5,2) (9,2) Y Y Y Y Before Rotation After Rotation 10 10 10 10 5 5 5 5 X X X X 0 0 0 0 5 5 5 5 10 10 10 10 • Visual representation Before After Rotate a shape: rotate every vertex of the shape
Summary • Translation: P’ = P + D • Scaling: P’ = S P • Rotation: P’ = R P Homogeneous Coordinates: P(x,y,w) (x,y) to (x,y,w) : (x,y,w) to (x,y)
y’= y + dy w’=1 x’= x + dx • P’’ = T(dx2 , dy2)P’ • = T(dx2 , dy2) T(dx1 , dy1) P • = T(dx2+dx1, dy2+dy1) P
Scaling P’=S(Sx, Sy)P • P’’ = S(Sx2 , Sy2)P’ • = S(Sx2 , Sy2)S(Sx1 , Sy1) P • = S(Sx2Sx1, Sy2Sy1)P
Rotation • P’=R()P P’’=R(2)R(1)PP”=R(2+1)P
Shear Transformation:SHx(a) and SHy(b) P’=SHx(a)P • Shear in x against y by a (or an angle). • x’ = x+ay • y’ = y w’=1
P’=SHy(b)P • Shear in y against x by b (or an angle). • x’=x • y’=y + bx • w’=1.
Y Y Y 10 10 10 5 5 5 X X X 0 0 0 5 5 5 10 10 10 Sheared in x Before Shear Sheared in y
Rigid-body Transformation: T and R. • change: location, orientation; • not change: size, angle between elements. Affine Transformation: S, SH • change: size, location, angle; • not change: line (parallelism). • Note: uniform scaling is between the two. It changes size but not angle. • So far, our S, R, SH are all around the origin.
y x After translation of P1 to origin y y P1 x x After rotation After translation To P1 • Composition of 2D Transformation Rotate the house around P1 For every vertex (P) on the object: P’ = T(P1)R()T(-P1)P y
y y y P1 x x x Original house P1 Translate P1 to origin Scale y y P2 x x Translate to final position P2 Rotate Scale and rotate the house around P1 and move it to P2
For every vertex (P) on the object: P’ = T(P2) R()S(Sx,Sy)T(-P1)P. • Swap the order of operations:not permitted, except uniform scaling (sx=sy) can be swapped with rotation.
y Maximum range of screen coordinates y Viewport 2 Window Viewport 1 x x World coordinates Window in world coordinates Window translated to origin Window scale to size of viewport Screen coordinates Translated by (u,v) to final position y y Window Window x x Screen coordinates World coordinates 5.4 Window-to-Viewport Transformation world-coordinate: inches, feet etc & screen-coordinate: pixels
y x z • Matrix Representation of 3D Transformation Translation: Scaling:
Rotation, around Z-axis: Rotation, around X-axis: Rotation, around Y-axis:
P( x, y, z ) x xp P’(xp, yp, zp) z d z (0,0,0) Projection Plane (View Plane) Projection: Project 3D objects on to a 2D surface
xp= x’ / w’ = x / (z/d + 1) • yp= y’ / w’ = y / (z/d + 1)
P1 P2 P’1 z P’2 Foreshortening: The size of the projected object becomes smaller when the object moves away from the eye. Perspective Projection: the projection that has the foreshortening effect.
0 Parallel Projection: d , lines of sight become parallel P1 0 z P2 View Plan (0,0,0)