TKWNT+5
=v
=u
=l
#1
:n
x
:v
35.35533905932737
63.63961030678927
91.92388155425117
56.56854249492379
45.96194077712558
35.35533905932737
E
#2
:n
y
:v
21.21320343559642
-7.071067811865472
21.21320343559643
21.21320343559642
31.81980515339463
21.21320343559642
E
#3
:n
xold
:v
10
50
50
25
10
10
E
#4
:n
yold
:v
40
40
80
55
55
40
E
#5
:n
t
:v
E
#6
:n
t#1
:v
E
#7
:n
t#2
:v
E
#8
:n
t#3
:v
E
#9
:n
m
:v
E
#10
:n
m#1
:v
E
#11
:n
m#2
:v
E
#12
:n
@x
:v
E
#13
:n
@y
:v
E
#14
:n
@yy
:v
E
#15
:n
m#3
:v
E
=f
#1
:n
make_identity
:c
Create a 3 x 3 identity matrix
:t
Procedure
:i
idm
#2
:n
translate
:c
Translate in x and y directions
:t
Procedure
:i
dx,dy
#3
:n
rotate
:c
Rotate "a" degrees about a fixed point
:t
Procedure
:i
a,xr,yr
#4
:n
scale
:c
Apply scaling factors wrt a fixed point
:t
Procedure
:i
sx,sy,xf,yf
#5
:n
update_t
:c
Update composite transformation matrix
:t
Procedure
#6
:n
transform_pts
:c
Transform coord lists (with over-writing)
:t
Procedure
#7
:n
save
:c
Save the original coordinates
:t
Procedure
#8
:n
restore
:c
Restore the original coordinates
:t
Procedure
#9
:n
graph_prep
:c
Prepares lists to plot old and new coords
:t
Procedure
#10
:n
CleanUp
:c
Blanks calculated lists
:t
Procedure
#1
:n
make_identity
:z
;This procedure creates a 3x3 identity matrix
call $midentity(idm,3)
return ; <++ because following statements replaced with single $ function
for i = 1 to 3
for j = 1 to 3
if i = j then idm[i][j] = 1 else idm[i][j] = 0
next j
next i
/E
E
#2
:n
translate
:z
; This procedure updates the transformation matrix to allow a translation
; x = dx and y = dy
call make_identity('m)
'm[3][1] = dx
'm[3][2] = dy
call update_t()
/E
E
#3
:n
rotate
:z
; This procedure updates the transformation matrix to allow a rotation
; of "a" DEGREES about a fixed point xr, yr
call make_identity('m)
ca = cosd(a)
sa = sind(a)
'm[1][1] = ca
'm[1][2] = sa
'm[2][1] = -sa
'm[2][2] = ca
'm[3][1] = xr*(1 - ca) + yr*sa
'm[3][2] = yr*(1 - ca) - xr*sa
call update_t()
/E
E
#4
:n
scale
:z
; This procedure updates the transformation matrix to allow scaling in
; the x and y directions of sx and sy wrt a fixed point xf, yf
call make_identity('m)
'm[1][1] = sx
'm[2][2] = sy
'm[3][1] = (1 - sx)*xf
'm[3][2] = (1 - sy)*yf
call update_t()
/E
E
#5
:n
update_t
:z
; Procedure to update the transformation matrix by performing [t] = [t]*[m]
call $mmproduct('t,'m,'t)
return;<++ because the $ function replaces all following statements
for i = 1 to 3
for j = 1 to 3
'temp[i][j] = 't[i][1]*'m[1][j] + 't[i][2]*'m[2][j] + 't[i][3]*'m[3][j]
next j
next i
for i = 1 to 3
for j = 1 to 3
't[i][j] = 'temp[i][j]
next j
next i
for i = 1 to 3
call delete('temp[i])
next i
call delete('temp)
/E
E
#6
:n
transform_pts
:z
; This procedure transforms the x and y coordinate lists according to
; the current composite transformation matrix. The original coordinate lists
; are overwritten.
for i = 1 to length('xold)
tempx = 'x[i]*'t[1][1] + 'y[i]*'t[2][1] + 't[3][1]
tempy = 'x[i]*'t[1][2] + 'y[i]*'t[2][2] + 't[3][2]
('x[i], 'y[i]) = (tempx, tempy)
next i
; The following statements are an alternative to the previous loop;
; more statements but perhaps more clarity.
'V1[3] = 1 ;<++ third homogeneous coord in [x y 1]
for i = 1 to length('xold)
( 'V1[1], 'V1[2]) = ('x[i], 'y[i]); <++ make a vector of the coords of the point
call $vmproduct('V1,'t,'V2)
('x[i], 'y[i]) = ('V2[1], 'V2[2]); <++ retrieve the coords from the transformed vector
next i
call delete('V1, 'V2)
/E
11
12
13
14
15
16
17
E
#7
:n
save
:z
call listcopy('x,'xold)
call listcopy('y,'yold)
/E
E
#8
:n
restore
:z
call blank('x)
call blank('y)
call listcopy('xold,'x)
call listcopy('yold,'y)
/E
E
#9
:n
graph_prep
:z
call blankm('@x,'@y,'@yy)
call listcopy('xold, '@x)
call listcopy('yold, '@y)
L = length('x)
call listcopy('x, '@x, 1,L, L+2)
call listcopy('y, '@yy, 1,L, L+2)
/E
E
#10
:n
CleanUp
:z
call blankm('t,'t#1,'t#2,'t#3,'m,'m#1,'m#2,'@x,'@y,'@yy,'m#3)
/E
E
=r
#1
:r
;*Documentation (Dive from here)
:s
C
#2
:r
; Note: plots have been set up for a working area of -100,100 to 100,100
:s
C
#3
:r
; This can be changed if desired. Remember to use isotropic scaling.
:s
C
#4
:r
call restore( )
#5
:r
call make_identity('t)
#6
:r
call translate(-10,20)
:s
C
#7
:r
call rotate(-45,0,0)
#8
:r
call scale(1,1.5,20,20)
:s
C
#9
:r
call transform_pts( )
#10
:r
call graph_prep()
=p
#1
:n
NewCoords
:t
Line chart
:i
""
:s
Yes
:z
Both
:g
No
:q
No
:l
Isotropic
:w
""
:h
"X"
:v
"Y"
:a
-100,100
:b
-100,100
:x
x
:e
,0,0,0,0,0
:p
0
:q
0
:c
0
:b
0
:o
0
:u
#1
:y
y
:f
1
:p
Lines
:c
"*"
:m
0
:k
0
:r
1
:n
0
E
:m
E
:k
E
#2
:n
OldCoords
:t
Line chart
:i
""
:s
Yes
:z
Both
:g
No
:q
No
:l
Isotropic
:w
""
:h
"X"
:v
"Y"
:a
-100,100
:b
-100,100
:x
xold
:e
,0,0,0,0,0
:p
0
:q
0
:c
0
:b
0
:o
0
:u
#1
:y
yold
:f
1
:p
Lines
:c
"*"
:m
0
:k
0
:r
1
:n
0
E
:m
E
:k
E
#3
:n
Both
:t
Line chart
:i
""
:s
Yes
:z
Both
:g
No
:q
No
:l
Isotropic
:w
""
:h
"X"
:v
"Y"
:a
-100,100
:b
-100,100
:x
@x
:e
,0,0,0,0,0
:p
0
:q
0
:c
0
:b
0
:o
0
:u
#1
:y
@y
:f
1
:p
Lines
:c
"*"
:m
0
:k
0
:r
1
:n
0
#2
:y
@yy
:f
1
:p
Lines
:c
"*"
:m
0
:k
1
:r
1
:n
0
E
:m
E
:k
E
=t
#1
:n
T_matrix
:v
Horizontal
:t
"Transformation matrix"
:u
#1
:l
t#1
:w
10
:h
""
#2
:l
t#2
:w
10
:h
""
#3
:l
t#3
:w
10
:h
""
E
#2
:n
M_matrix
:v
Horizontal
:t
"Temporary Matrix written by each individual transformation"
:u
#1
:l
m#1
:w
10
:h
""
#2
:l
m#2
:w
10
:h
""
#3
:l
m#3
:w
10
:h
""
E
#3
:n
Coords
:v
Vertical
:t
"Coordinates (will be transformed)"
:u
#1
:l
x
:w
10
:h
""
#2
:l
y
:w
10
:h
""
E
#4
:n
OldCoords
:v
Vertical
:t
"Original coordinates can be saved here with call save( )"
:u
#1
:l
xold
:w
10
:h
""
#2
:l
yold
:w
10
:h
""
E
=n
=c
#1
:n
Documentation
:z
30
The purpose of this model is to show how homogeneous coordinates simplify
2D coordinate transformations. The steps in applying a series of transformations
to lists of x and y coordinates are as follows:
(1) Intialize the transformation matrix with a call to make_identity('t)
(2) Call the desired transformations in order. See the Function Sheet
for the argument definitions.
(3) Call transform_pts() to convert the coordinates with the composite
transformation matrix t.
With each call of a transformation (translate, scale, etc.), the t matrix
is updated. When all of the transformations have been done, the points
themselves are transformed.
Note that the x & y coords are overwritten by the transform_pts() function.
The original coordinates stored in list x & y can be saved with call save()
and restored with call restore(). This allows the user to experiment with
different transformations on the same object.
A reasonable object to experiment with has coords:
x = 20, 60, 60, 35, 20, 20
y = 20, 20, 60, 35, 35, 20
To see the effect of one or more transformations use cancel to eliminate
some of the rules as desired.
To solve the model press F9.
Ref: Hearn and Baker, Computer Graphics, Prentice Hall 1986.
rjferg49 at sympatico.ca 01 Nov 2000, updated 09 Apr 07
#2
:n
Challenge
:z
2
When you understand how this model works, add a procedure to mirror the
object about a line. Your procedure should provide coords to plot the mirror line.
#3
:n
What_are_HC
:z
7
Several Internet sites have explanations of homogeneous coords.
For 2D work, the coords of a point in HC can be (x,y,1). By adding the third constant coordinate all
transformations can be done by matrix multiplication. With HC a series of transformations is
"stored" in a 3x3 transformation matrix. The points themselves are transformed in one final operation.
With ordinary (x,y) coords, any translations would require adding dx and dy to all points making for a
more complex and slower procedure.
=g
#1
:c
.000001
:i
10
:t
1
:y
No
=d
:c
E
:f
0
:v
E
:g
0.000001
:i
1000
:t
100
:p
0.000001
:r
5.00
:e
0
:d
1
:s
0
:n
0
:a
0
=s
:r
0
:v
%Tv,f,0,1,0,0,3
%Or,f,5,1,0,1,0
%Xf,f,5,0,0,2,0,154,154,959,647,320,713,0,0,0,0,2,-1,0,0,2,-15,400,34,0,0,0,0,TK Arial,4,16,26,38,80
%Xl,f,0,0,0,2,0,110,110,893,605,0,689,-1,-1,0,0,4,-1,0,0,2,-16,400,34,0,0,0,161,Arial,4,10,21,31,98
%Xp,f,0,0,0,2,0,132,132,915,627,160,713,-1,-1,0,0,5,-1,0,0,2,-16,400,34,0,0,0,161,Arial,3,13,25,99
%Xt,f,0,0,0,2,0,154,154,937,649,320,689,-1,-1,0,0,6,-1,0,0,2,-16,400,34,0,0,0,161,Arial,2,15,100
%Xn,f,0,0,0,2,0,176,176,959,671,800,713,-1,-1,0,0,7,-1,0,0,2,-16,400,34,0,0,0,161,Arial,2,15,100
%Xc,f,0,0,0,2,0,198,198,981,693,480,713,-1,-1,0,0,8,-1,0,0,2,-16,400,34,0,0,0,161,Arial,3,15,22,99
%Xv,f,0,1,0,1,3,0,0,805,493,0,713,0,0,0,0,0,-1,0,0,2,-15,400,34,0,0,0,0,TK Arial,6,3,13,21,31,41,80
%Xu,f,0,0,0,2,0,96,395,132,431,160,689,0,0,0,0,3,-1,0,0,2,-15,400,34,0,0,0,0,TK Arial,5,10,20,34,48,80
%Xm,f,0,0,0,0,0,546,395,582,431,640,713,0,0,0,0,9,-1,0,0,2,0,0,0,0,0,0,0,,0
%Xr,f,5,1,0,2,0,0,0,805,493,-1,-1,0,0,0,0,1,-1,0,0,1,-15,400,34,0,0,0,0,TK Arial,2,2,85
%X ,f,0,0,0,0,0,22,22,827,515,-1,-1,0,0,0,5,5,2,0,0,1,-13,400,34,0,0,0,161,Arial,0
%X ,f,0,0,0,2,0,44,44,849,537,-1,-1,0,0,0,1,8,0,0,0,1,-16,400,34,0,0,0,161,Arial,1,100
\G,0,1023,1566,1,-1,-1
\G,0,2046,1566,1,-1,-1
\C,0,2046,0,0,3