Transforms
Transforms
Lecture 2 Geometric
Lecture 2 Geometric
Transformations
Computer
ati et
Transformations
s
rm eom
ns ric
Le Tr
tio et
ct an
ma om
ur sf
or e
e or
sf G
sfo 2 G
2 ma
Graphics
an e 2
Ge ti
Tr tur
om on
c
et s
Le
ric
Tr ture
an
c
Le
Geometric
Transformations by
Brian Wyvill
Lecture 2 Geometric
Transformations ns ic
io tr
University of Calgary
at me
rm eo
fo G
ns 2
ra e
T ur
ct
Le
ENEL/CPSC 1 1.
2D Transformations TRANSLATION
2,3
2,1
x new = x + d x y new = y + d y
x x new dx
P = P new = Y T = d so P new = P + T
y new y
F&VD.2 p168
ENEL/CPSC 2 .
2D Transformations SCALING
2,3
2,1
x new = x * S x y new = y * S y
2,3
2,1
ENEL/CPSC 5 .
Homogeneous Coordinates
We have : P new = P + T Translation
P new = S * P Scaling
P new = R * P Rotation
x x
In homogeneous coordinates becomes:
y y
W
x,y,W represents the same point as x’,y’,W if one is a multiple of the other.
Thus (2,3,6) is the same as (4,6,12) since
2/6 = 4/12 and 3/6 = 6/12 (W != 0)
Dividing the homogeneous point by W gives the Cartesian point (x/W, y/W)
Note the dimension change.
ENEL/CPSC 6 .
Homogeneous Representation of 2D transforms
W
3 space Line representing all the triples
of the form (tx, ty, tW) t!=0 each 2D
homogeneous point represents a line
of points in 3 space.
x
W=1 plane
ENEL/CPSC 7 .
Homogeneous Representation of 2D transforms
continued
Points are now 3 element column vectors so we need 3x3 matrices
to represent tranformations. The translation equation becomes:
xnew 1 0 dx x
ynew = 0 1 dy * y
1 0 0 1 1
ENEL/CPSC 8 .
Column Vector vs. Row Vector
Column vectors take less space on the page in book format. However
for the assignment premultiplying matrics as they are read from the
user is easier than stacking the matrics. Use whichever convention you
feel most comfortable with but be consistent.
ENEL/CPSC 9 .
Homogeneous Representation of 2D transforms
continued
xnew 1 0 dx x
ynew = 0 1 dy * y Translation
1 0 0 1 1
xnew Sx 0 0 x
ynew = 0 Sy 0 * y Scaling
1 0 0 1 1
2,1
1 0 1
Next translation T1 = 0 1 1
0 0 1
P’ = T0 * P
P’’ = T1 * P’ so P’’ = T1 * T0 * P 1 0 1
0 1 2
Matrix product T1 * T0 is 0 0 1
ENEL/CPSC 1 1.
Composing Geometric Transformations
continued
Matrix product also known as concatanation, compounding or composition
of matrices. Consider a set of n=1000000 points P representing the following
piano mesh. The points are scaled by matrix S and rotated by matrix R and
translated by matrix T.
ENEL/CPSC 1 2.
Order of Concatanation
2
2 1
1
0,0 0,0
2
1 2
1
0,0 0,0
ENEL/CPSC 1 3.
Order of Concatanation
0,0 0,0
0,0 0,0
ENEL/CPSC 1 5.
Vector Library continued
ENEL/CPSC 1 6.
Vector Library continued
Matrix Functions
void matMake(int xdesc, REFVTX value, double rotation,
REFv3dMATRIX matrix);
void matAssign(REFv3dMATRIX a, REFv3dMATRIX b);
WVTX hmatPointMult(REFv3dMATRIX matrix, WVTX p);
VTX matPointMult( REFv3dMATRIX matrix, VTX p);
void matClear(REFv3dMATRIX matrix);
void matPrint(FILE *outfile, char *buf, REFv3dMATRIX mat);
REFv3dMATRIX matCreate();
REFv3dMATRIX matIdentity( register REFv3dMATRIX matrix);
REFv3dMATRIX matCopy( register REFv3dMATRIX m);
REFv3dMATRIX matNth(REFv3dMATRIX mat, int n);
REFv3dMATRIX matPremult(REFv3dMATRIX a,
REFv3dMATRIX b, REFv3dMATRIX c);
Print Functions
/* print routines n= no newline f = full precision */
void v3dPVec( FILE *fp, char *buf, VTX v);
void v3dPVecn(FILE *fp, char *buf, VTX v);
void v3dPfVec( FILE *fp, char *buf, VTX v);
void v3dPfVecn(FILE *fp, char *buf, VTX v);
void v3dPPlane(FILE *fp, char *buf, REFPLANE p);
void v3dPPoly(FILE *fp, char *buf, REFPOLY p);
void v3d2gl(VTX v, double *gv); /* convert to gl double [3] */
ENEL/CPSC 1 7.