4
4
Provides an interface for implementing Affine transformations of Cartesian
5
5
coordinates. To implement an AbstractAffineTransformation, you must define
6
6
7
- matrix (trans)
8
- translation (trans)
7
+ transformation_matrix (trans)
8
+ translation_vector (trans)
9
9
10
10
where the resulting transformation is (equivalent to)
11
11
12
- trans(x) -> matrix (trans) * x + translation (trans)
12
+ trans(x) -> transformation_matrix (trans) * x + translation_vector (trans)
13
13
14
14
Specific implementations may provide equivalent specializations of `call`, etc,
15
- for optimization purposes. The function `translation_reverse ()` is provided,
15
+ for optimization purposes. The function `translation_vector_reverse ()` is provided,
16
16
such that
17
17
18
- trans(x) -> matrix (trans) * (x + translation_reverse (trans))
18
+ trans(x) -> transformation_matrix (trans) * (x + translation_vector_reverse (trans))
19
19
20
20
(See also AffineTransformation, AbstractLinearTransformation, Translation)
21
21
"""
22
22
abstract AbstractAffineTransformation <: Transformation
23
23
24
- matrix (trans:: AbstractAffineTransformation ) = error (" AbstractAffineTransformation $(typeof (trans)) must implement matrix ()" )
25
- translation (trans:: AbstractAffineTransformation ) = error (" AbstractAffineTransformation $(typeof (trans)) must implement translation ()" )
26
- translation_reverse (:: AbstractAffineTransformation ) = matrix (trans) \ translation (trans)
24
+ transformation_matrix (trans:: AbstractAffineTransformation ) = error (" AbstractAffineTransformation $(typeof (trans)) must implement transformation_matrix ()" )
25
+ translation_vector (trans:: AbstractAffineTransformation ) = error (" AbstractAffineTransformation $(typeof (trans)) must implement translation_vector ()" )
26
+ translation_vector_reverse (:: AbstractAffineTransformation ) = transformation_matrix (trans) \ translation_vector (trans)
27
27
28
28
# Default implementations
29
29
@compat function (trans:: AbstractAffineTransformation )(x)
30
- matrix (trans) * x + translation (trans)
30
+ transformation_matrix (trans) * x + translation_vector (trans)
31
31
end
32
32
33
33
# Could try do similar for transform_deriv_params()?
34
34
35
- transform_deriv (trans:: AbstractAffineTransformation , x) = matrix (trans)
35
+ transform_deriv (trans:: AbstractAffineTransformation , x) = transformation_matrix (trans)
36
36
37
37
function Base. inv (trans:: AbstractAffineTransformation )
38
- Minv = inv (matrix (trans))
39
- AffineTransformation (Minv, - Minv * translation (trans))
40
- end
41
-
42
- function compose (t1:: AbstractAffineTransformation , t2:: AbstractAffineTransformation )
43
- AffineTransformation (matrix (t1) * matrix (t2), translation (t1) + matrix (t1) * translation (t2))
38
+ Minv = inv (transformation_matrix (trans))
39
+ AffineTransformation (Minv, - Minv * translation_vector (trans))
44
40
end
45
41
46
42
function Base. isapprox (t1:: AbstractAffineTransformation , t2:: AbstractAffineTransformation , kwargs... )
47
- isapprox (matrix (t1), matrix (t2); kwargs... ) &&
48
- isapprox (translation (t1), translation (t2); kwargs... )
43
+ isapprox (transformation_matrix (t1), transformation_matrix (t2); kwargs... ) &&
44
+ isapprox (translation_vector (t1), translation_vector (t2); kwargs... )
49
45
end
50
46
51
47
"""
54
50
Provides an interface for implementing linear transformations of Cartesian
55
51
coordinates. To implement an AbstractLinearTransformation, you must define
56
52
57
- matrix (trans)
53
+ transformation_matrix (trans)
58
54
59
55
where the resulting transformation is (equivalent to)
60
56
61
- trans(x) -> matrix (trans) * x
57
+ trans(x) -> transformation_matrix (trans) * x
62
58
63
59
Specific implementations may provide equivalent specializations of `call`, etc,
64
60
for optimization purposes.
@@ -67,59 +63,127 @@ for optimization purposes.
67
63
"""
68
64
abstract AbstractLinearTransformation <: AbstractAffineTransformation
69
65
70
- matrix (trans:: AbstractLinearTransformation ) = error (" AbstractLinearTransformation $(typeof (trans)) must implement matrix ()" )
71
- function translation (trans:: AbstractLinearTransformation )
72
- m = matrix (trans)
66
+ transformation_matrix (trans:: AbstractLinearTransformation ) = error (" AbstractLinearTransformation $(typeof (trans)) must implement transformation_matrix ()" )
67
+ function translation_vector (trans:: AbstractLinearTransformation )
68
+ m = transformation_matrix (trans)
73
69
s = size (m, 1 )
74
70
T = eltype (m)
75
71
return zeros (T, s)
76
72
end
77
- function translation_reverse (trans:: AbstractLinearTransformation )
78
- m = matrix (trans)
73
+ function translation_vector_reverse (trans:: AbstractLinearTransformation )
74
+ m = transformation_matrix (trans)
79
75
s = size (m, 2 )
80
76
T = eltype (m)
81
77
return zeros (T, s)
82
78
end
83
79
84
80
# Default implementations
85
81
@compat function (trans:: AbstractLinearTransformation )(x)
86
- matrix (trans) * x
82
+ transformation_matrix (trans) * x
87
83
end
88
84
89
85
# transform_deriv() identical to that provided by AbstractAffineTransformation
90
86
91
- Base. inv (trans:: AbstractLinearTransformation ) = LinearTransformation (inv (matrix (trans)))
87
+ function Base. isapprox (t1:: AbstractLinearTransformation , t2:: AbstractLinearTransformation , kwargs... )
88
+ isapprox (transformation_matrix (t1), transformation_matrix (t2); kwargs... )
89
+ end
92
90
93
- compose (t1:: AbstractLinearTransformation , t2:: AbstractLinearTransformation ) = LinearTransformation (matrix (t1) * matrix (t2))
91
+ # These functions are remove any reference to unnecessary calls to
92
+ # translation_vector(::LinearTransformation) from the AbstractAffineTransformations
93
+ # interface:
94
94
95
- function Base. isapprox (t1:: AbstractLinearTransformation , t2:: AbstractLinearTransformation , kwargs... )
96
- isapprox (matrix (t1), matrix (t2); kwargs... )
95
+ function Base. isapprox (t1:: AbstractAffineTransformation , t2:: AbstractLinearTransformation , kwargs... )
96
+ isapprox (transformation_matrix (t1), transformation_matrix (t2); kwargs... ) &&
97
+ isapprox (norm (translation_vector (t1)), 0 ; kwargs... )
98
+ end
99
+
100
+ function Base. isapprox (t1:: AbstractLinearTransformation , t2:: AbstractAffineTransformation , kwargs... )
101
+ isapprox (transformation_matrix (t1), transformation_matrix (t2); kwargs... ) &&
102
+ isapprox (norm (translation_vector (t2)), 0 ; kwargs... )
97
103
end
98
104
105
+ #=
106
+ """
107
+ abstract AbstractRotation <: AbstractLinearTransformation
99
108
109
+ Provides an interface for implementing rotations of Cartesian coordinates. To
110
+ implement an AbstractRotation, you must define
100
111
101
- # These functions are remove any reference to unnecessary calls to
102
- # translation(::LinearTransformation) from the AbstractAffineTransformations
103
- # interface:
112
+ transformation_matrix(trans)
104
113
105
- function compose (t1:: AbstractAffineTransformation , t2:: AbstractLinearTransformation )
106
- AffineTransformation (matrix (t1) * matrix (t2), translation (t1))
114
+ where the resulting transformation is (equivalent to)
115
+
116
+ trans(x) -> transformation_matrix(trans) * x
117
+
118
+ Specific implementations may provide equivalent specializations of `call`, etc,
119
+ for optimization purposes. The major difference with AbstractLinearTransformation
120
+ is that the matrix is assumed to be orthogonal/unitary for the purpose of
121
+ inverting the transformation.
122
+
123
+ (See also Rotation, AxisRotation, AbstractLinearTransformation)
124
+ """
125
+ abstract AbstractRotation <: AbstractLinearTransformation
126
+
127
+ transformation_matrix(trans::AbstractRotation) = error("AbstractRotation $(typeof(trans)) must implement transformation_matrix()")
128
+ =#
129
+
130
+
131
+ """
132
+ abstract AbstractTranslation <: AbstractAffineTransformation
133
+
134
+ A transformation that encapsulates the translation of Cartesian points.
135
+ Implementations must define:
136
+
137
+ translation_vector(trans)
138
+
139
+ where the translation goes as
140
+
141
+ trans(x) -> x + translation_vector(trans)
142
+
143
+ (See also Translation, AbstractAffineTransformation, AffineTransformation)
144
+ """
145
+ abstract AbstractTranslation <: AbstractAffineTransformation
146
+
147
+ @inline transformation_matrix (:: AbstractTranslation ) = I
148
+
149
+ @compat function (trans:: AbstractTranslation )(x)
150
+ x + translation_vector (trans)
107
151
end
108
152
109
- function compose (t1:: AbstractLinearTransformation , t2:: AbstractAffineTransformation )
110
- AffineTransformation (matrix (t1) * matrix (t2), matrix (t1) * translation (t2))
153
+
154
+ # ##################
155
+ # ## Translation ###
156
+ # ##################
157
+ """
158
+ Translation(dv) <: AbstractAffineTransformation
159
+ Translation(dx, dy) (2D)
160
+ Translation(dx, dy, dz) (3D)
161
+
162
+ Construct the `Translation` transformation for translating Cartesian points.
163
+ """
164
+ immutable Translation{T} <: AbstractTranslation
165
+ dx:: T
111
166
end
167
+ Translation (x:: Tuple ) = Translation (Vec (x))
168
+ Translation (x,y) = Translation (Vec (x,y))
169
+ Translation (x,y,z) = Translation (Vec (x,y,z))
170
+ Base. show (io:: IO , trans:: Translation ) = print (io, " Translation$((trans. dx... )) " )
112
171
113
- function Base. isapprox (t1:: AbstractAffineTransformation , t2:: AbstractLinearTransformation , kwargs... )
114
- isapprox (matrix (t1), matrix (t2); kwargs... ) &&
115
- isapprox (norm (translation (t1)), 0 ; kwargs... )
172
+ translation_vector (trans:: Translation ) = trans. dx
173
+
174
+ # Generic definitions that capture all `Translation`s.
175
+ Base. inv (trans:: AbstractTranslation ) = Translation (- translation_vector (trans))
176
+
177
+ function compose (trans1:: AbstractTranslation , trans2:: AbstractTranslation )
178
+ Translation (translation_vector (trans1) + translation_vector (trans2))
116
179
end
117
180
118
- function Base. isapprox (t1:: AbstractLinearTransformation , t2:: AbstractAffineTransformation , kwargs... )
119
- isapprox (matrix (t1), matrix (t2); kwargs... ) &&
120
- isapprox (norm (translation (t2)), 0 ; kwargs... )
181
+ function transform_deriv_params (trans:: Translation , x)
182
+ I
121
183
end
122
184
185
+
186
+
123
187
"""
124
188
LinearTransformation <: AbstractLinearTransformation
125
189
@@ -131,11 +195,17 @@ immutable LinearTransformation{MatrixT} <: AbstractLinearTransformation
131
195
M:: MatrixT
132
196
end
133
197
134
- LinearTransformation (trans:: AbstractLinearTransformation ) = LinearTransformation (matrix (trans))
198
+ LinearTransformation (trans:: AbstractLinearTransformation ) = LinearTransformation (transformation_matrix (trans))
135
199
136
200
Base. show (io:: IO , trans:: LinearTransformation ) = print (io, " LinearTransformation($(trans. M) )" ) # TODO make this output more petite
137
201
138
- @inline matrix (trans:: LinearTransformation ) = trans. M
202
+ @inline transformation_matrix (trans:: LinearTransformation ) = trans. M
203
+
204
+ # Generic definitions
205
+
206
+ Base. inv (trans:: AbstractLinearTransformation ) = LinearTransformation (inv (transformation_matrix (trans)))
207
+
208
+ compose (t1:: AbstractLinearTransformation , t2:: AbstractLinearTransformation ) = LinearTransformation (transformation_matrix (t1) * transformation_matrix (t2))
139
209
140
210
141
211
"""
@@ -157,11 +227,11 @@ immutable AffineTransformation{MatrixT, VectorT} <: AbstractAffineTransformation
157
227
v:: VectorT
158
228
end
159
229
160
- matrix (trans:: AffineTransformation ) = trans. M
161
- translation (trans:: AffineTransformation ) = trans. v
230
+ transformation_matrix (trans:: AffineTransformation ) = trans. M
231
+ translation_vector (trans:: AffineTransformation ) = trans. v
162
232
163
233
function AffineTransformation (trans:: AbstractAffineTransformation )
164
- AffineTransformation (matrix (trans), translation (trans))
234
+ AffineTransformation (transformation_matrix (trans), translation_vector (trans))
165
235
end
166
236
167
237
# We can create an Affine transformation corresponding to the differential
@@ -179,46 +249,35 @@ end
179
249
180
250
Base. show (io:: IO , trans:: AffineTransformation ) = print (io, " AffineTransformation($(trans. M) , $(trans. v) )" ) # TODO make this output more petite
181
251
182
-
183
-
184
- # ##################
185
- # ## Translation ###
186
- # ##################
187
- """
188
- Translation(dv) <: AbstractAffineTransformation
189
- Translation(dx, dy) (2D)
190
- Translation(dx, dy, dz) (3D)
191
-
192
- Construct the `Translation` transformation for translating Cartesian points.
193
- """
194
- immutable Translation{T} <: AbstractAffineTransformation
195
- dx:: T
252
+ function compose (t1:: AbstractTranslation , t2:: AbstractLinearTransformation )
253
+ AffineTransformation (transformation_matrix (t2), translation_vector (t1))
196
254
end
197
- Translation (x:: Tuple ) = Translation (Vec (x))
198
- Translation (x,y) = Translation (Vec (x,y))
199
- Translation (x,y,z) = Translation (Vec (x,y,z))
200
- Base. show (io:: IO , trans:: Translation ) = print (io, " Translation$((trans. dx... )) " )
201
255
202
- @inline matrix ( :: Translation ) = I
203
- @inline translation (trans :: Translation ) = trans . dx
204
- @inline translation (trans :: Translation ) = trans . dx
256
+ function compose (t1 :: AbstractLinearTransformation , t2 :: AbstractTranslation )
257
+ AffineTransformation ( transformation_matrix (t1), transformation_matrix (t1) * translation_vector (t2))
258
+ end
205
259
206
- @compat function (trans :: Translation )(x )
207
- x + trans . dx
260
+ function compose (t1 :: AbstractAffineTransformation , t2 :: AbstractAffineTransformation )
261
+ AffineTransformation ( transformation_matrix (t1) * transformation_matrix (t2), translation_vector (t1) + transformation_matrix (t1) * translation_vector (t2))
208
262
end
209
263
210
- @compat (trans:: Translation )(x:: Tuple ) = Tuple (Vec (x) + trans. dx)
264
+ function compose (t1:: AbstractAffineTransformation , t2:: AbstractLinearTransformation )
265
+ AffineTransformation (transformation_matrix (t1) * transformation_matrix (t2), translation_vector (t1))
266
+ end
211
267
212
- Base. inv (trans:: Translation ) = Translation (- trans. dx)
268
+ function compose (t1:: AbstractLinearTransformation , t2:: AbstractAffineTransformation )
269
+ AffineTransformation (transformation_matrix (t1) * transformation_matrix (t2), transformation_matrix (t1) * translation_vector (t2))
270
+ end
213
271
214
- function compose (trans1 :: Translation , trans2 :: Translation )
215
- Translation (trans1 . dx + trans2 . dx )
272
+ function compose (t1 :: AbstractAffineTransformation , t2 :: AbstractTranslation )
273
+ AffineTransformation ( transformation_matrix (t1), translation_vector (t1) + transformation_matrix (t1) * translation_vector (t2) )
216
274
end
217
275
218
- function transform_deriv_params (trans :: Translation , x )
219
- I
276
+ function compose (t1 :: AbstractTranslation , t2 :: AbstractAffineTransformation )
277
+ AffineTransformation ( transformation_matrix (t2), translation_vector (t1) + translation_vector (t2))
220
278
end
221
279
280
+
222
281
# ###################
223
282
# ## 2D Rotations ###
224
283
# ###################
@@ -268,12 +327,12 @@ end
268
327
Polar (x. r, x. θ + trans. angle)
269
328
end
270
329
271
- function matrix (trans:: Rotation2D )
330
+ function transformation_matrix (trans:: Rotation2D )
272
331
@fsa [ trans. cos - trans. sin;
273
332
trans. sin trans. cos ]
274
333
end
275
334
276
- function matrix (trans:: Rotation2D )
335
+ function transformation_matrix (trans:: Rotation2D )
277
336
@fsa [ trans. cos - trans. sin;
278
337
trans. sin trans. cos ]
279
338
end
@@ -284,7 +343,7 @@ function transform_deriv{T}(trans::Rotation2D, x::Polar{T})
284
343
end
285
344
286
345
function transform_deriv_params (trans:: Rotation2D , x)
287
- # 2x1 transformation matrix
346
+ # 2x1 transformation transformation_matrix
288
347
Mat (- trans. sin* x[1 ] - trans. cos* x[2 ],
289
348
trans. cos* x[1 ] - trans. sin* x[2 ] )
290
349
end
362
421
363
422
@compat (trans:: Rotation )(x:: Tuple ) = Tuple (trans (Vec (x)))
364
423
365
- matrix (trans:: Rotation ) = trans. matrix
424
+ transformation_matrix (trans:: Rotation ) = trans. matrix
366
425
@inline matrix (trans:: Rotation2D ) = trans. matrix
367
426
368
427
@@ -565,7 +624,7 @@ function transform_deriv(trans::RotationXY, x)
565
624
trans. sin trans. cos Z;
566
625
Z Z I]
567
626
end
568
- function matrix (trans:: RotationXY )
627
+ function transformation_matrix (trans:: RotationXY )
569
628
Z = zero (trans. cos)
570
629
I = one (trans. cos)
571
630
@fsa [ trans. cos - trans. sin Z;
@@ -580,7 +639,7 @@ function transform_deriv(trans::RotationYZ, x)
580
639
Z trans. cos - trans. sin;
581
640
Z trans. sin trans. cos ]
582
641
end
583
- function matrix (trans:: RotationYZ )
642
+ function transformation_matrix (trans:: RotationYZ )
584
643
Z = zero (trans. cos)
585
644
I = one (trans. cos)
586
645
@fsa [ I Z Z;
@@ -595,7 +654,7 @@ function transform_deriv(trans::RotationZX, x)
595
654
Z I Z ;
596
655
- trans. sin Z trans. cos ]
597
656
end
598
- function matrix (trans:: RotationZX )
657
+ function transformation_matrix (trans:: RotationZX )
599
658
Z = zero (trans. cos)
600
659
I = one (trans. cos)
601
660
@fsa [ trans. cos Z trans. sin;
0 commit comments