summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-04-28 16:01:13 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-04-28 18:43:08 +0200
commit30b6637fe84813ad7119e92dd49df7e12692c694 (patch)
tree324ad07ddf43596cd6ef65e321d7ea297459a9b3 /docs
parent5423ccd321c1c84b0e7736b10b2fe9eeb1833e16 (diff)
Document the gesture frame logic
Add some notes on the math of the gesture frame computations. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'docs')
-rw-r--r--docs/gestures.txt58
-rw-r--r--docs/pivot.txt146
2 files changed, 204 insertions, 0 deletions
diff --git a/docs/gestures.txt b/docs/gestures.txt
new file mode 100644
index 0000000..5a1eb45
--- /dev/null
+++ b/docs/gestures.txt
@@ -0,0 +1,58 @@
1Introduction
2------------
3
4This document describes how the gestures are extracted from multi-finger
5actions. The process is divided into gestural transformations, gesture
6recognition, and gesture instantiation.
7
8Gestural Transformations
9------------------------
10
11All two-finger transformations are extracted. These are all exact, in the
12sense that continuously transforming the original finger positions, frame
13per frame, will exactly follow the actual finger positions.
14
15In addition to two-finger transformations, a global gesture is also
16extracted. The rotation and scaling is taken from the contact pair with the
17longest distance between contacts. This approximates the behavior of a
18region, such that complex transformations could, in principle, be happening
19inside the region, but at a distance, the transformation will look like it
20was performed with two fingers.
21
22At each time step, a gestural transformation is goverened by rotation,
23scaling and translation. The point around which rotation and scaling is
24performed is called the pivot. To form as natural gestures as possible,
25this point always lies within the area formed by the contacts themselves.
26It is placed at the point which, after rotation and scaling, leaves the
27transformed contacts as close to the actual positions as possible. The
28translation, or drag, is always a fraction of the movement of the center
29point. The fraction is called moveness, and is related to the distance
30between the pivot and the center point. When the pivot is at the center
31point, the moveness is one and the drag is the same as the center movement.
32When the pivot is at one of the contacts, as in rotation around a finger,
33the moveness is zero, and consequently the drag is zero. The relations
34between the pivot, the moveness and the drag are detailed in the document
35pivot.txt.
36
37Gesture Recognition
38-------------------
39
40Each gestural transformation can give rise to one or several gesture
41primitives. Based on the rotation, scaling, moveness and drag values, the
42gesture primitives drag, pinch and rotate are recognized. The onset of a
43gesture primitive is governed by a threshold and a timeout. Basically, if
44performed distinctly enough, the gesture will be triggered, and will remain
45active until a finger is lifted or added.
46
47Gesture Instantiation
48---------------------
49
50Given a set of detected gesture primitives, only some will trigger actual
51gesture events. First, the set of available primitives are matched against
52available listeners. Primitives not listened for are dropped. The remaining
53set is arranged according to priority. A pointer gesture has lower priority
54than a two-finger gesture, which has lower priority than a tap, for
55instance. As long as the gesture primitives of higher priority are expected
56but not activated, all gestures are held back. Once one of the highest
57priority primitives are activated, all primitives of lower priority are
58cancelled, and events are emitted.
diff --git a/docs/pivot.txt b/docs/pivot.txt
new file mode 100644
index 0000000..b945dd6
--- /dev/null
+++ b/docs/pivot.txt
@@ -0,0 +1,146 @@
1The pivot, p, is defined as the point, within the convex hull of the
2contacts, which, after rotation and scaling, leaves the transformed
3contacts as close to the actual positions as possible.
4
5Let r_i be the starting points and s_i the actual ending points in a
6transformation. Let D be the scaling, and R the rotation. Then, minimizing
7
8L(p) = sum_i |D R (r_i - p) + p - s_i|^2 / N
9
10yields the pivot. Let
11
12rm = sum_i r_i / N,
13p = rm + u,
14q_i = s_i - rm - D R (r_i - rm),
15
16and we get
17
18L(p) = sum_i |(1 - D R) u - q_i|^2 / N.
19
20With
21
22L0 = sum_i norm2(q_i) / N,
23T = (1 - D R)' (1 - D R),
24m = sum_i q_i / N,
25
26we can write this as
27
28L(p) = L0 + u' T u - 2 m' (1 - D R) u.
29
30To handle the constraint, we can approximate the hull with a circle
31centered at rm. If we pick the average radius, P, the constraint becomes
32
33|u| < P.
34
35Relaxing [1] the expression (h >= 0) yields
36
37L(p, h) = L0 + u' T u - 2 m' (1 - D R) u + h (|u|^2 - P^2),
38
39leading to the linear equation
40
41(T + h) u = (1 - D R)' m.
42
43Further,
44
45sm = sum_i s_i / N,
46m = sum_i (s_i - rm - D R (r_i - rm)) / N = sm - rm,
47
48thus m is the average displacement. In words, the pivot is the average
49position plus a correction depending on the average displacement.
50
51*
52
53Some algebra solves the equation,
54
55D' = D,
56[D, R] = 0,
57R = S + C,
58S' = -S,
59C' = C,
60R + R' = 2 C,
61T = (1 - D R)' (1 - D R) = 1 + D^2 - 2 D C,
62
63which is a simple diagonal scaling operator. With
64
65a = 1 - D C,
66b = D S,
67
68we can write this as
69
70T = (1 - DC)^2 + D^2(1 - C^2) = (1 - DC)^2 + D^2 S^2 = a^2 + b^2.
71
72Similarly, we can write
73
74(1 - D R)' = ((a, b), (-b, a)),
75
76and thusly,
77
78u = Q(h) m,
79
80with
81
82Q(h) = ((a, b), (-b, a)) / (a^2 + b^2 + h).
83
84When D R = 1, it follows that a^2 + b^2 = 0, and the relaxation ensures
85that u is finite.
86
87*
88
89The drag is found by minimizing
90
91E(d) = sum_i | D R (r_i - p) + p + d - s_i |^2 / N,
92E(d) = d^2 + 2 d' ((1 - D R) u - m) + E0,
93
94which leads to the linear equation
95
96d = m - (1 - D R) u.
97
98Explicitly,
99
100d = m - (a ux - b uy, a uy + b ux).
101
102Inserting the expression for u yields, after some algebra,
103
104d = m (1 - (a^2 + b^2) / (a^2 + b^2 + h)).
105
106When h = 0, d = 0, as expected.
107
108When a^2 + b^2 = 0, d = m, also as expected.
109
110For constrained cases, the drag is a fraction of the average displacement.
111
112*
113
114Time to look at measures for the relaxation parameter. Since d depends on
115h, we can write the correction u(h) in terms of d instead. After som
116algebra,
117
118|u(h)| = (|m| - |d|) / sqrt(a^2 + b^2).
119
120Conversely, d(h) can be written in terms of the constrained u(h) as
121
122d(h) = m (1 - sqrt(a^2 + b^2) |u(h)| / |m|).
123
124Since |u(0)| = |m| / sqrt(a^2 + b^2), we obtain
125
126d(h) = m (1 - |u(h)| / |u(0)|).
127
128*
129
130We can now write down an explicit recipe for determining the pivot (p) and
131drag (d), given the transformation parameters a and b.
132
133w = (a mx + b my, a my - b mx).
134
135If |w| = 0, then u = 0. Consequently p = rm, d = m, and we are done. Else,
136
137u = w |m|^2 / |w|^2,
138
139t = P / |u|.
140
141If t >= 1, then p = rm + u, d = 0, and we are done. Else,
142
143p = rm + t u,
144d = (1 - t) m.
145
146[1] See Lagrange relaxation