diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-04-28 16:01:13 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-04-28 18:43:08 +0200 |
| commit | 30b6637fe84813ad7119e92dd49df7e12692c694 (patch) | |
| tree | 324ad07ddf43596cd6ef65e321d7ea297459a9b3 /docs/pivot.txt | |
| parent | 5423ccd321c1c84b0e7736b10b2fe9eeb1833e16 (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/pivot.txt')
| -rw-r--r-- | docs/pivot.txt | 146 |
1 files changed, 146 insertions, 0 deletions
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 @@ | |||
| 1 | The pivot, p, is defined as the point, within the convex hull of the | ||
| 2 | contacts, which, after rotation and scaling, leaves the transformed | ||
| 3 | contacts as close to the actual positions as possible. | ||
| 4 | |||
| 5 | Let r_i be the starting points and s_i the actual ending points in a | ||
| 6 | transformation. Let D be the scaling, and R the rotation. Then, minimizing | ||
| 7 | |||
| 8 | L(p) = sum_i |D R (r_i - p) + p - s_i|^2 / N | ||
| 9 | |||
| 10 | yields the pivot. Let | ||
| 11 | |||
| 12 | rm = sum_i r_i / N, | ||
| 13 | p = rm + u, | ||
| 14 | q_i = s_i - rm - D R (r_i - rm), | ||
| 15 | |||
| 16 | and we get | ||
| 17 | |||
| 18 | L(p) = sum_i |(1 - D R) u - q_i|^2 / N. | ||
| 19 | |||
| 20 | With | ||
| 21 | |||
| 22 | L0 = sum_i norm2(q_i) / N, | ||
| 23 | T = (1 - D R)' (1 - D R), | ||
| 24 | m = sum_i q_i / N, | ||
| 25 | |||
| 26 | we can write this as | ||
| 27 | |||
| 28 | L(p) = L0 + u' T u - 2 m' (1 - D R) u. | ||
| 29 | |||
| 30 | To handle the constraint, we can approximate the hull with a circle | ||
| 31 | centered at rm. If we pick the average radius, P, the constraint becomes | ||
| 32 | |||
| 33 | |u| < P. | ||
| 34 | |||
| 35 | Relaxing [1] the expression (h >= 0) yields | ||
| 36 | |||
| 37 | L(p, h) = L0 + u' T u - 2 m' (1 - D R) u + h (|u|^2 - P^2), | ||
| 38 | |||
| 39 | leading to the linear equation | ||
| 40 | |||
| 41 | (T + h) u = (1 - D R)' m. | ||
| 42 | |||
| 43 | Further, | ||
| 44 | |||
| 45 | sm = sum_i s_i / N, | ||
| 46 | m = sum_i (s_i - rm - D R (r_i - rm)) / N = sm - rm, | ||
| 47 | |||
| 48 | thus m is the average displacement. In words, the pivot is the average | ||
| 49 | position plus a correction depending on the average displacement. | ||
| 50 | |||
| 51 | * | ||
| 52 | |||
| 53 | Some algebra solves the equation, | ||
| 54 | |||
| 55 | D' = D, | ||
| 56 | [D, R] = 0, | ||
| 57 | R = S + C, | ||
| 58 | S' = -S, | ||
| 59 | C' = C, | ||
| 60 | R + R' = 2 C, | ||
| 61 | T = (1 - D R)' (1 - D R) = 1 + D^2 - 2 D C, | ||
| 62 | |||
| 63 | which is a simple diagonal scaling operator. With | ||
| 64 | |||
| 65 | a = 1 - D C, | ||
| 66 | b = D S, | ||
| 67 | |||
| 68 | we can write this as | ||
| 69 | |||
| 70 | T = (1 - DC)^2 + D^2(1 - C^2) = (1 - DC)^2 + D^2 S^2 = a^2 + b^2. | ||
| 71 | |||
| 72 | Similarly, we can write | ||
| 73 | |||
| 74 | (1 - D R)' = ((a, b), (-b, a)), | ||
| 75 | |||
| 76 | and thusly, | ||
| 77 | |||
| 78 | u = Q(h) m, | ||
| 79 | |||
| 80 | with | ||
| 81 | |||
| 82 | Q(h) = ((a, b), (-b, a)) / (a^2 + b^2 + h). | ||
| 83 | |||
| 84 | When D R = 1, it follows that a^2 + b^2 = 0, and the relaxation ensures | ||
| 85 | that u is finite. | ||
| 86 | |||
| 87 | * | ||
| 88 | |||
| 89 | The drag is found by minimizing | ||
| 90 | |||
| 91 | E(d) = sum_i | D R (r_i - p) + p + d - s_i |^2 / N, | ||
| 92 | E(d) = d^2 + 2 d' ((1 - D R) u - m) + E0, | ||
| 93 | |||
| 94 | which leads to the linear equation | ||
| 95 | |||
| 96 | d = m - (1 - D R) u. | ||
| 97 | |||
| 98 | Explicitly, | ||
| 99 | |||
| 100 | d = m - (a ux - b uy, a uy + b ux). | ||
| 101 | |||
| 102 | Inserting the expression for u yields, after some algebra, | ||
| 103 | |||
| 104 | d = m (1 - (a^2 + b^2) / (a^2 + b^2 + h)). | ||
| 105 | |||
| 106 | When h = 0, d = 0, as expected. | ||
| 107 | |||
| 108 | When a^2 + b^2 = 0, d = m, also as expected. | ||
| 109 | |||
| 110 | For constrained cases, the drag is a fraction of the average displacement. | ||
| 111 | |||
| 112 | * | ||
| 113 | |||
| 114 | Time to look at measures for the relaxation parameter. Since d depends on | ||
| 115 | h, we can write the correction u(h) in terms of d instead. After som | ||
| 116 | algebra, | ||
| 117 | |||
| 118 | |u(h)| = (|m| - |d|) / sqrt(a^2 + b^2). | ||
| 119 | |||
| 120 | Conversely, d(h) can be written in terms of the constrained u(h) as | ||
| 121 | |||
| 122 | d(h) = m (1 - sqrt(a^2 + b^2) |u(h)| / |m|). | ||
| 123 | |||
| 124 | Since |u(0)| = |m| / sqrt(a^2 + b^2), we obtain | ||
| 125 | |||
| 126 | d(h) = m (1 - |u(h)| / |u(0)|). | ||
| 127 | |||
| 128 | * | ||
| 129 | |||
| 130 | We can now write down an explicit recipe for determining the pivot (p) and | ||
| 131 | drag (d), given the transformation parameters a and b. | ||
| 132 | |||
| 133 | w = (a mx + b my, a my - b mx). | ||
| 134 | |||
| 135 | If |w| = 0, then u = 0. Consequently p = rm, d = m, and we are done. Else, | ||
| 136 | |||
| 137 | u = w |m|^2 / |w|^2, | ||
| 138 | |||
| 139 | t = P / |u|. | ||
| 140 | |||
| 141 | If t >= 1, then p = rm + u, d = 0, and we are done. Else, | ||
| 142 | |||
| 143 | p = rm + t u, | ||
| 144 | d = (1 - t) m. | ||
| 145 | |||
| 146 | [1] See Lagrange relaxation | ||
