summaryrefslogtreecommitdiff
path: root/ipl/procs/xforms.icn
blob: 96d973cb045316557cdc5a6bd2061ff3214f3cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
############################################################################
#
#	File:     xforms.icn
#
#	Subject:  Procedures to do matrix transformations
#
#	Author:   Stephen W. Wampler and Ralph E. Griswold
#
#	Date:     March 25, 2002
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  These procedures produce matrices for affine transformation in two
#  dimensions and transform point lists.
#
#  A point list is a list of Point() records.  See gobject.icn.
#
############################################################################
#
#  Links:  matrix
#
############################################################################

link matrix

procedure transform(p, M)		#: transform point list by matrix
   local pl, i

   # convert p to a matrix for matrix multiply...

   every put((pl := [[]])[1], (!p)|1.0)	# the 1.0 makes it homogeneous

   # do the conversion...

   pl := mult_matrix(pl, M)

   # convert list back to a point list...

   p := copy(p)
   every i := 1 to *p do
      p[i] := pl[1][i]

   return p

end

procedure transform_points(pl,M)	#: transform point list
   local xformed

   every put(xformed := [], !transform(!pl,M))

   return xformed

end
   
procedure set_scale(x, y)		#: matrix for scaling
   local M

   M := identity_matrix(3,3)

   M[1][1] := x
   M[2][2] := y

   return M

end

procedure set_trans(x, y)		#: matrix for translation
   local M

   M := identity_matrix(3,3)

   M[*M][1] := x
   M[*M][2] := y

   return M

end

procedure set_xshear(x)			#: matrix for x shear
   local M

   M :=  identity_matrix(3,3)

   M[1][2] := x

   return M

end

procedure set_yshear(y)			#: matrix for y shear
   local M

   M := identity_matrix(3,3)

   M[2][1] := y

   return M

end

procedure set_rotate(x)			#: matrix for rotation
   local M

   M := identity_matrix(3,3)
   M[1][1] := cos(x)
   M[2][2] := M[1][1]
   M[1][2] := sin(x)
   M[2][1] := -M[1][2]

   return M

end