| 1 |
#set page(width: 16cm, margin: 0.5em, height: auto) |
| 2 |
#let definition(content) = box(fill: luma(92%), width: 100%, inset: 0.5em, stroke: black)[#content] |
| 3 |
|
| 4 |
#let comment(body) = [#text(size: 0.8em)[(#body)]] |
| 5 |
|
| 6 |
#let pr = $nu$ |
| 7 |
#let time = $t$ |
| 8 |
|
| 9 |
== Stroke end |
| 10 |
|
| 11 |
The position modeling algorithm will lag behind the raw input by some distance. This algorithm iterates the previous |
| 12 |
dynamical system a few additional time using the raw input position as the anchor to allow a `catch up` of the stroke |
| 13 |
(though this prediction is only given by `predict`, so is not part of the `results` and becomes obsolete on the next |
| 14 |
input). |
| 15 |
|
| 16 |
*Algorithm* :Stroke end\ |
| 17 |
#[*Input*: |
| 18 |
- Final anchor position $p["end"] = (x["end"],y["end"])$ #comment(text(black)[From the original input stream]) |
| 19 |
- final tip state $q_f ["end"] = (p_f ["end"]= (x_f ["end"],y_f ["end"]),v_f ["end"], a_f ["end"])$ #comment[#text( |
| 20 |
fill: black, |
| 21 |
)[returned from the physical modeling from the last section, $dot_f$ signifies that we are looking at the filtered output]] |
| 22 |
- $K_"max"$ max number of iterations #comment[#text(fill: black)[`sampling_end_of_stroke_max_iterations`]] |
| 23 |
- $Delta_"target"$ the target time delay between stroke #comment[#text(fill: black)[1/`sampling_min_output_rate`]] |
| 24 |
- $d_"stop"$ stopping distance #comment[#text(fill: black)[`sampling_end_of_stroke_stopping_distance`]] |
| 25 |
- $k_"spring"$ and $k_"drag"$ the modeling coefficients |
| 26 |
] |
| 27 |
#[*initialize* the vector $q_o$ with $q_0 [0] = lr((underbrace(p_f ["end"], p_o [0]), |
| 28 |
underbrace(v_f ["end"], v_o [0]), underbrace(a_f ["end"], a_0 [0])), size: #1em)$]\ |
| 29 |
#[*initialize* $Delta t = Delta_"target"$]\ |
| 30 |
#[*for* $1<= k <= K_"max"$]\ |
| 31 |
- #[*calculate* the next candidate |
| 32 |
$ |
| 33 |
a_c &= (p ["end"] - p_o ["end"])/(k_"spring") - k_"drag" v_0 ["end"]\ |
| 34 |
v_c &= v_o [0] + Delta t a_c\ |
| 35 |
p_c &= p_o [0] + Delta v_c |
| 36 |
$ |
| 37 |
]\ |
| 38 |
- #[*if* $norm(p_c - p["end"])< d_"stop"$ #comment[#text(black)[further iterations won't be able to catch up and won't move closer to the anchor, we stop here]]], |
| 39 |
- #[*return* $q_0$]\ |
| 40 |
- #[*endif*]\ |
| 41 |
- #[*if* |
| 42 |
$angle.l p_c - p_o ["end"], p["end"] - p_o ["end"] angle.r < norm(p_c - p_o ["end"])$ |
| 43 |
#comment[#text(black)[we've overshot the anchor, we retry with a smaller step]] |
| 44 |
]\ |
| 45 |
- #[$Delta t <- (Delta t)/2$], |
| 46 |
- #[*continue* #comment[this candidate will be discarded, try again with a smaller time step instead]], |
| 47 |
- #[*else*]\ |
| 48 |
- #[$q_0["end +1"] = (p_c, v_c, q_c)$ #comment[#text(black)[We append the result to the end of the $q_0$ vector]]]\ |
| 49 |
- #[*endif*]\ |
| 50 |
- #[*if* $norm(p_c - p["end"]) < d_"stop"$], |
| 51 |
- #[*return* |
| 52 |
#comment[We are within tolerance of the anchor, we stop iterating]], |
| 53 |
- #[*endif*], |
| 54 |
#[*Output* : ${q_o [k] = (s_o [k], v_o [k], a_o [k]), 0 <= k <= n (<= K_"max" - 1)}$] |