Stroke end

The position modeling algorithm will lag behind the raw input by some distance. This algorithm iterates the previous dynamical system a few additional time using the raw input position as the anchor to allow a catch up of the stroke (though this prediction is only given by predict, so is not part of the results and becomes obsolete on the next input).

Algorithm :Stroke end
Input:

initialize the vector q o q_{o} with q 0 [ 0 ] = ( p f [ end ] p o [ 0 ] , v f [ end ] v o [ 0 ] , a f [ end ] a 0 [ 0 ] ) q_{0}\lbrack 0\rbrack = \left. \left( \underset{p_{o}\lbrack 0\rbrack}{\underbrace{p_{f}\left\lbrack \text{end} \right\rbrack}},\underset{v_{o}\lbrack 0\rbrack}{\underbrace{v_{f}\left\lbrack \text{end} \right\rbrack}},\underset{a_{0}\lbrack 0\rbrack}{\underbrace{a_{f}\left\lbrack \text{end} \right\rbrack}} \right) \right.
initialize Δ t = Δ target \Delta t = \Delta_{\text{target}}
for 1 k K max 1 \leq k \leq K_{\text{max}}
- calculate the next candidate a c = p [ end ] p o [ end ] k spring k drag v 0 [ end ] v c = v o [ 0 ] + Δ t a c p c = p o [ 0 ] + Δ v c \begin{aligned} a_{c} & = \frac{p\left\lbrack \text{end} \right\rbrack - p_{o}\left\lbrack \text{end} \right\rbrack}{k_{\text{spring}}} - k_{\text{drag }}v_{0}\left\lbrack \text{end} \right\rbrack \\ v_{c} & = v_{o}\lbrack 0\rbrack + \Delta ta_{c} \\ p_{c} & = p_{o}\lbrack 0\rbrack + \Delta v_{c} \end{aligned}


- if p c p [ end ] < d stop \left. \parallel{p_{c} - p\left\lbrack \text{end} \right\rbrack} \right.\parallel < d_{\text{stop}} (further iterations won’t be able to catch up and won’t move closer to the anchor, we stop here), - return q 0 q_{0}
- endif

- else
- q 0 [ e n d + 1 ] = ( p c , v c , q c ) q_{0}\lbrack end\ +1\rbrack = \left( p_{c},v_{c},q_{c} \right) (We append the result to the end of the q 0 q_{0} vector)
- endif

Output : { q o [ k ] = ( s o [ k ] , v o [ k ] , a o [ k ] ) , 0 k n ( K max 1 ) } \left\{ q_{o}\lbrack k\rbrack = \left( s_{o}\lbrack k\rbrack,v_{o}\lbrack k\rbrack,a_{o}\lbrack k\rbrack \right),0 \leq k \leq n\left( \leq K_{\text{max }} - 1 \right) \right\}