Professional Documents
Culture Documents
Cc php bin i 2D
Gii thiu
x ' f (x , y )
y ' g (x , y )
P(x,y)
Q(x,y)
y ' dx ey f
Biu din php bin i Affine di dng ma trn:
x '
a b c x
y ' d e f y Q T .P
1
0 0 1 1
Thng thng, chng ta ch kho st php bin Affine nn ta
thng dng thut ng php bin i ng l php bin i
Affine.
Q
try
trx
x ' x trx
y ' y try
Ma trn bin i ca php tnh tin:
1 0 trx
i hng i tng.
Php quay gm c tm quay C, gc quay .
Bin i im P thnh Q sao cho:
P v Q nm trn ng trn tm C,
Gc PCQ bng
cos
x
'
cos
sin
sin
sin
cos
0
0
1
=180
0
x ' x
T 1800
y ' y
1 0 0
0 1 0
0
0 1
C(xc,yc)
O
T(-xc,-yc)
T()
T(xc,yc)
Q
10
cos
sin
0
sin
cos
0
(1 cos )x c sin y c
sin x c (1 cos )y c
1
11
sx
T (s x , s y ) 0
0
Co gin i tng
x ' sx x
y ' sy y
0
sy
0
12
13
Thu nh
Phng to
14
y ' y
s y 1
x ' x
y ' y
s x 1
sy 1
1 0 0
0 1 0
0 0 1
1 0 0
0 1 0
0 0 1
15
1 shx
x
'
sh
y
T
sh
,
0
0 1
x
y
'
0 0
x ' x
T
0
,
sh
shy
y
y
'
sh
x
y
y
0 0
1 0
0 1
16
x ' x shx y
T
sh
,
sh
shy
x
y
y
'
sh
x
y
y
shx
1
0
0
1
17
Bi tp
Bin i i tng 2D
points
color
center
H ta i tng
H ta thc
18
Bi tp
Bin i i tng 2D (cont.)
H ta thc
Tnh tin i tng bng vect tr, thc cht l tnh tin tm ca i tng
Quay i tng theo gc angle, thc cht l quay cc nh ca a gic
19
Bi tp
Bin i i tng 2D (cont.)
Cu trc d liu
#define MAXNUMPOINTS
10
struct Point2D
{
double x, y;
};
struct Object
{
Point2D center;
Point2D points[MAXNUMPOINTS];
int numOfPoints;
int color;
Point2D tr;
double angle;
//
};
20
Bi tp
Bin i i tng 2D (cont.)
tr
21
Bi tp
Bin i i tng 2D (cont.)
Quay i tng: void roatateObject(Object &o);
Quay cc nh ca a gic ca i tng theo theo gc angle :
rotatePoints(o.points[i], o.angle);
Object o;
initObject(o);
while (!kbhit())
{
o.color = CYAN;
drawObject(o);
delay(50);
o.color = BLACK;
drawObject(o);
translateObject(o);
ratateObject(o);
//
}
22