@@ -3,6 +3,10 @@ module Transform2D where
33It is used primarily with the `groupTransform` function from `Graphics.Collage` and
44allows you to do things like rotation, scaling, translation, shearing, and reflection.
55
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+
610# Basic Transforms
711@docs identity, matrix, rotation
812
@@ -18,8 +22,8 @@ data Transform2D = Transform2D
1822not change anything, but it can come in handy as a default or
1923base case.
2024
21− / 1 0 \
22− \ 0 1 /
25+ / 1 0 0 \
26+ \ 0 1 0 /
2327-}
2428identity : Transform2D
2529identity = Native.Transform2D.identity
@@ -29,10 +33,10 @@ such as scales, shears, reflections, and translations.
2933
3034 matrix a b c d dx dy
3135
32− / a b \
33− \ c d /
36+ / a b dx \
37+ \ c d dy /
3438
35−And `dx` and `dy` are the translation values.
39+Note that `dx` and `dy` are the translation values.
3640-}
3741matrix : Float -> Float -> Float -> Float -> Float -> Float -> Transform2D
3842matrix = Native.Transform2D.matrix
@@ -40,12 +44,41 @@ matrix = Native.Transform2D.matrix
4044{-| Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
4145Given an angle t, it creates a counterclockwise rotation matrix:
4246
43− / cos t -sin t \
44− \ sin t cos t /
47+ / cos t -sin t 0 \
48+ \ sin t cos t 0 /
4549-}
4650rotation : Float -> Transform2D
4751rotation = Native.Transform2D.rotation
4852
53+{-| Creates a transformation matrix for translation:
54+
55+ translation x y
56+
57+ / 1 0 x \
58+ | 0 1 y |
59+ \ 0 0 1 /
60+-}
61+translation : Float -> Float -> Transform2D
62+translation x y = matrix 1 0 0 1 x y
63+
64+{-| Creates a transformation matrix for scaling by a all directions:
65+
66+ scale s
67+
68+ / s 0 0 \
69+ \ 0 s 0 /
70+-}
71+scale : Float -> Transform2D
72+scale s = matrix s 0 0 s 0 0
73+
74+{-| Creates a transformation for horizontal scaling -}
75+scaleX : Float -> Transform2D
76+scaleX x = matrix x 0 0 1 0 0
77+
78+{-| Creates a transformation for vertical scaling -}
79+scaleY : Float -> Transform2D
80+scaleY y = matrix y 0 0 1 0 0
81+
4982{-| Multiplies two transforms together:
5083
5184 multiply a b
@@ -54,4 +87,4 @@ rotation = Native.Transform2D.rotation
5487 \ a21 a22 / \ b21 b22 /
5588-}
5689multiply : Transform2D -> Transform2D -> Transform2D
57−multiply = Native.Transform2D.multiply
90+multiply = Native.Transform2D.multiply