04 – Geometric Transformations • Overview • Geometric Primitives – Points, Lines, Planes • 2D Geometric Transformations – Translation, Rotation, Scaling, Affine, Projective • 3D Geometric Transformations – Rotation About Arbitrary Axes Overview • Before we can understand how digital images are formed we must review some geometry – Geometric primitives – 2D and 3D geometric transformations • Then we will discuss how cameras create digital images of the world – 3D to 2D projection – Image sampling Geometric Primitives • 2D points – x=(x,y) in Euclidean coordinates – x=(x,y,w) in homogeneous coordinates where x=x/w and y=y/w • 3D points – x=(x,y,z) in Euclidean coordinates – x=(x,y,z,w) in homogeneous coordinates where x=x/w , y=y/w and z=z/w Geometric Primitives • 2D lines – ax+by+c=0 is basic 2D line equation – (a,b,c).(x,y,1)=0 using dot product notation – (nx,ny,d) .(x,y,1)=0 where n=(nx,ny) is unit normal to line and d is distance from line to origin Geometric Primitives • 3D lines – r = (1-l)p + lq is parametric line equation – In this case p, q and r are 3D points – When l = [0..1] we have 3D line segment Geometric Primitives • 3D planes – ax+by+cz+d=0 is basic 3D plane equation – (a,b,c,d).(x,y,z,1)=0 using dot product notation – (nx,ny,nz,d) .(x,y,z,1)=0 where n=(nx,ny,nz) is unit normal and d is distance from plane to origin 2D Geometric Transformations • The simplest geometric transformations that occur in the 2D plane are: translation, Euclidean, similarity, affine and projective 2D Geometric Transformations • 2D Translation: x' = x + t (x ', y') = (x, y) + (t x , t y ) é 1 0 t ù x ê ú x ' = ê 0 1 ty úx ê ú êë 0 0 1 úû 2D Geometric Transformations • 2D Scaling: x' = s × x (x ', y') = (sx, sy) é s 0 0 ê x' = ê 0 s 0 ê 0 0 1 ë ù ú úx ú û 2D Geometric Transformations • 2D Rotation: x' = R × x (x ', y') = (x cosq - ysin q , x sin q + y cosq ) é cosq -sin q 0 ù ê ú x' = ê sin q cosq 0 ú x ê 0 0 1 úû ë 2D Geometric Transformations • 2D Rotation around arbitrary point: – Translate to origin, rotate, translate back x' = T(cx,cy) × R × T(-cx,-cy) × x x ' = (x - cx)cosq - (y - cy)sin q + cx y' = (x - cx)sinq + (y - cy)cosq + cy é 1 0 cx ùé cosq -sin q 0 ùé 1 0 -cx ù ê úê úê ú x' = ê 0 1 cy úê sinq cosq 0 úê 0 1 -cy ú x ê 0 0 1 úê 0 úê 0 0 1 ú 0 1 ë ûë ûë û 2D Geometric Transformations • 2D Scaling around arbitrary point: – Translate to origin, scale, translate back x' = T(cx,cy) × S× T(-cx,-cy) × x x ' = (x - cx)s + cx y' = (x - cx)s + cy é 1 0 cx ùé s 0 0 ùé 1 0 -cx ù ê úê úê ú x' = ê 0 1 cy úê 0 s 0 úê 0 1 -cy ú x ê 0 0 1 úê 0 0 1 úê 0 0 1 ú ë ûë ûë û 2D Geometric Transformations • 2D Euclidean (rotation + translation): – Preserves distances between points x' = T(tx,ty) × R × x (x ', y') = (x cosq - ysin q + t x , x sin q + y cosq + t y ) é cosq ê x' = ê sin q ê êë 0 -sin q cosq 0 tx ù ú ty úx ú 1 úû 2D Geometric Transformations • 2D Similarity (scaling + rotation + translation): – Preserves angles between lines x' = T(tx,ty) × R × S× x (x ', y') = (s x cosq - s ysinq + t x , s x sinq + s y cosq + t y ) é s × cosq ê x' = ê s × sinq ê 0 êë -s × sinq s × cosq 0 tx ù ú ty úx ú 1 úû 2D Geometric Transformations • 2D Affine: – Parallel lines remain parallel x' = Ax (x ', y') = (a00 x + a01 y + a02 , a10 x + a11 y + a12 ) é a ê 00 x' = ê a10 ê êë 0 a01 a11 0 a02 ù ú a12 ú x ú 1 úû 2D Geometric Transformations • 2D Projective: – Straight lines remain straight x' = Hx æh x+h y+h h x+h y+h ö 01 02 11 12 (x ', y') = ç 00 , 10 ÷ è h20 x + h21 y + h22 h20 x + h21 y + h22 ø é h ù h h 01 02 ê 00 ú x' = ê h10 h11 h12 ú x ê ú êë h20 h21 h22 úû 2D Geometric Transformations • 2D Transformation hierarchy 3D Geometric Transformations • 3D translation is very similar to 2D translation – There are now 3 coordinates to translate (tx,ty,tz) – We use 4x4 matrix to perform operation • 3D scaling is very similar to 2D scaling – We still only have one scale factor S – We use 4x4 matrix to perform operation 3D Geometric Transformations • There are three ways to perform 3D rotations – 1) Rotate about the X,Y,Z axes – 2) Rotate about an arbitrary axis – 3) Use unit quaternions to perform rotation • Option 1 is easiest to understand • Options 2 and 3 provide smoother motions 3D Geometric Transformations • 3D Rotation about Z axis: x' = R × x (x ', y', z') = (x cosq - ysinq , x sin q + y cosq , z) é cosq -sin q 0 0 ù ê ú sin q cosq 0 0 ú ê x' = x ê 0 0 1 0 ú ê 0 ú 0 0 1 ë û 3D Geometric Transformations • 3D Rotation about Y axis: x' = R × x (x ', y', z') = (x cosq + zsin q , y, -x sin q + z cosq ) é cosq 0 sin q 0 ù ê ú 0 1 0 0 ú x' = ê x ê -sin q 0 cosq 0 ú ê 0 ú 0 0 1 û ë 3D Geometric Transformations • 3D Rotation about X axis: x' = R × x (x ', y', z') = (x, y cosq - zsin q , ysin q + z cosq ) é 1 0 0 0 ù ê ú 0 cosq -sin q 0 ú ê x' = x ê 0 sin q cosq 0 ú ê 0 ú 0 0 1 ë û 3D Geometric Transformations • 3D Rotation about arbitrary axis in X-Y plane – – – – Find angle a between rotation axis and X axis Rotate around Z axis by -a degrees Rotate around X axis by desired angle q Rotate around Z axis by a degrees • Same approach works for rotations about an arbitrary axis in Y-Z plane or Z-X plane 3D Geometric Transformations • 3D Rotation about an arbitrary axis – – – – – Project arbitrary axis onto Y-Z plane Find angle b between projected axis and Y axis Rotate around X axis by -b degrees Now rotate about axis in X-Y plane Rotate around X axis by b degrees • Same approach can be used to project the arbitrary axis onto Y-Z plane or Z-X plane 3D Geometric Transformations • 3D Transformation hierarchy