on master help sign in
Unify matrices to 3x2 representation.
b44a34eMichael Sondergaard
libraries/Transform2D.elm+13−9
@@ -3,6 +3,10 @@ module Transform2D where
3It is used primarily with the `groupTransform` function from `Graphics.Collage` and
3It is used primarily with the `groupTransform` function from `Graphics.Collage` and
4allows you to do things like rotation, scaling, translation, shearing, and reflection.
4allows you to do things like rotation, scaling, translation, shearing, and reflection.
5
5
6+Note that all the matrices in this library are 3x3 matrices of homogeneous
7+coordinates, used for affine transformations. Since the third row as always 0 0
8+1, we omit this below.
9+
6# Basic Transforms
10# Basic Transforms
7@docs identity, matrix, rotation
11@docs identity, matrix, rotation
8
12
@@ -18,8 +22,8 @@ data Transform2D = Transform2D
18not change anything, but it can come in handy as a default or
22not change anything, but it can come in handy as a default or
19base case.
23base case.
20
24
21− / 1 0 \
25+ / 1 0 0 \
22− \ 0 1 /
26+ \ 0 1 0 /
23-}
27-}
24identity : Transform2D
28identity : Transform2D
25identity = Native.Transform2D.identity
29identity = Native.Transform2D.identity
@@ -29,10 +33,10 @@ such as scales, shears, reflections, and translations.
29
33
30 matrix a b c d dx dy
34 matrix a b c d dx dy
31
35
32− / a b \
36+ / a b dx \
33− \ c d /
37+ \ c d dy /
34
38
35−And `dx` and `dy` are the translation values.
39+Note that `dx` and `dy` are the translation values.
36-}
40-}
37matrix : Float -> Float -> Float -> Float -> Float -> Float -> Transform2D
41matrix : Float -> Float -> Float -> Float -> Float -> Float -> Transform2D
38matrix = Native.Transform2D.matrix
42matrix = Native.Transform2D.matrix
@@ -40,8 +44,8 @@ matrix = Native.Transform2D.matrix
40{-| Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
44{-| Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
41Given an angle t, it creates a counterclockwise rotation matrix:
45Given an angle t, it creates a counterclockwise rotation matrix:
42
46
43− / cos t -sin t \
47+ / cos t -sin t 0 \
44− \ sin t cos t /
48+ \ sin t cos t 0 /
45-}
49-}
46rotation : Float -> Transform2D
50rotation : Float -> Transform2D
47rotation = Native.Transform2D.rotation
51rotation = Native.Transform2D.rotation
@@ -61,8 +65,8 @@ translation x y = matrix 1 0 0 1 x y
61
65
62 scale a
66 scale a
63
67
64− / a 0 \
68+ / a 0 0 \
65− \ 0 a /
69+ \ 0 a 0 /
66-}
70-}
67scale : Float -> Transform2D
71scale : Float -> Transform2D
68scale a = matrix a 0 0 a 0 0
72scale a = matrix a 0 0 a 0 0