9
edits
Tag: Undo |
(Explain basic mechanism of Arctan Straining and how it constructs the Iwerlipse. Show Iwer's original proof, and equations for the Iwerlipse. Explain the proper history behind the discoveries.) |
||
| Line 1: | Line 1: | ||
The '''Iwerlipse''' is the range of positions Mario can occupy | The '''Iwerlipse''' is the range of positions Mario can occupy while he is in the air and cannot turn, assuming that drag is constant. The boundary of the Iwerlipse is reached by '''Arctan Straining''' - the optimal way of air straining that gives the greatest distance along a chosen angle <math>\omega</math> for a given number of frames <math>T</math>. For a single frame <math>T=1</math>, the Iwerlipse is an ellipse with half-width 10 (in the sideways direction) and half-height 1.5 (in the forwards direction). For general <math>T</math>, it resembles an ellipse with half-width <math>10T</math> and half-height <math>3T(T+1)/4</math>, but bulges at the corners, covering more area than an ellipse with the same dimensions. As shown by ''Grassdigger'', the shape is well approximated by a generalised superellipse, and thus ''Pannenkoek2012'' proposed calling this shape the Iwerlipse (pronounced eeverlipse /ˈivɜlɪps/) - a pun on the name of ''Iwer Sonsch'', who first discoverered that Arctan Straining was optimal in April 2018. | ||
==Basics== | |||
Arctan Straining gives the maximum possible distance along a target angle <math>\omega</math> that differs from the facing angle <math>\theta</math>, over a finite number of frames <math>T</math>. It is performed by choosing straining angles <math>\phi_t</math> (intendedYaw) such that | |||
<math>\ | <div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | ||
<math> | |||
\begin{align} | |||
\phi_t - \theta = | |||
\begin{cases} | |||
\arctan \left[\dfrac{10\tan(\omega - \theta)}{1.5(T+1-t)} \right] & \text{if } \cos(\omega-\theta) > 0, \\[14pt] | |||
\arctan \left[\dfrac{10\tan(\omega - \theta)}{1.5(T+1-t)} \right] + 180^\circ & \text{if } \cos(\omega-\theta) < 0, | |||
\end{cases} | |||
\end{align} | |||
</math> | |||
</div> | |||
<math>\ | with <math>t</math> being the frame number between <math>1</math> and <math>T</math>. (Usually only the top row of this equation is given, but since the <math>\arctan</math> function only gives results between <math>\pm 90^\circ</math>, we must add <math>180^\circ</math> to the result if the target angle is behind Mario.) | ||
Arctan straining is a result of two asymmetries in how Mario's forward velocity and sideways speed are updated | |||
* Forward velocity accelerates gradually over time, while sideways speed is reset every frame | |||
* Straining on a single frame has a weak effect on forward velocity (increasing velocity by a maximum of 1.5), but a strong effect on sideways speed for a single frame (setting sideways speed to a maximum of 10). | |||
In terms of total distance acquired along some direction, forward velocity is thus more effective over long periods of time, where it has time to accelerate to large values, whereas sideways speed is more effective over short periods of time. Optimal straining over many frames then involves straining mostly along the forwards direction to build up a large forward velocity, and then towards the end of the trajectory, transitioning into sideways straining to exploit the large sideways displacement obtainable in a single frame. | |||
==Update Equations== | |||
When Mario is in the air and cannot turn, the function <code>update_air_without_turn</code> is responsible for updating Mario's velocity variables from one frame, <math>t-1</math>, to the next, <math>t</math>. Without loss of generality, we can choose coordinates so that Mario's facing angle is zero. In other words, he is facing along the <math>z</math>-axis, while his sideways speed is directed along the <math>x</math>-axis. Mario's forward velocity, <math>v_t</math>, and position coordinates <math>z_t</math> and <math>x_t</math> are then updated via | |||
<div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | |||
<math>\begin{align} | |||
v_t &= v_{t-1} - D(v_{t-1}, \phi_t) + 1.5\cos(\phi_t),\\ | |||
z_t &= z_{t-1} + v_t,\\ x_t &= x_{t-1} + 10\sin(\phi_t), | |||
\end{align}</math> | |||
</div> | |||
where <math>\phi_t</math> is the straining angle (intendedYaw) on frame <math>t</math>. The total effect of drag is given by the coefficient <math>D</math>, determined by | |||
<math> | |||
D(v_{t-1}, \phi_t) = | |||
\begin{cases} | |||
-2.35 & \text{if } v_{t-1} < - 16.35 - 1.5 \cos(\phi_t),\\ | |||
-0.35 & \text{if } -16.35 - 1.5 \cos(\phi_t) \leq v_{t-1} \leq -0.35,\\ | |||
v_{t-1} & \text{if } -0.35 < v_{t-1} < 0.35,\\ | |||
0.35 & \text{if } 0.35 \leq v_{t-1} \leq D_\text{cap} + 0.35 - 1.5 \cos(\phi_t),\\ | |||
1.35 & \text{if } v_{t-1} > D_\text{cap} + 0.35 - 1.5 \cos(\phi_t). | |||
\end{cases} | |||
</math> | |||
where <math>D_\text{cap}</math> is a soft velocity cap equal to 48 for long jumps and 32 otherwise. | |||
In practice, these drag boundaries are far enough apart that the drag is often constant over large periods of time. In this case we can write Mario's position after <math>T</math> frames as | |||
<math> | <math>\begin{align} | ||
x_T &= x_0 + 10 \sum_{t=1}^{T} \sin(\phi_t),\\ | |||
z_T &= z_0 + v_0 T - D \sum_{t=1}^T t + 1.5 \sum_{t=1}^T \sum_{n=1}^t \cos(\phi_n). | |||
\end{align}</math> | |||
<math> | Using <math>\sum_{t=1}^T t = T(T+1)/2</math>, and by grouping terms of <math>\cos(\phi_t)</math>, the latter can be simplified to | ||
<math> z_T = z_0 + v_0 T - \frac{DT(T+1)}{2} + 1.5 \sum_{t=1}^T (T+1-t)\cos(\phi_t). </math> | |||
Notice that, since forward straining produces an acceleration that is not reset between frames, earlier frames have a stronger effect on the final <math>z</math> position than later frames. The effective strength is <math>1.5(T+1-t)</math>, i.e. 1.5 multiplied by the number of frames remaining (including the current frame), since the forward velocity gained on one frame produces a displacement also on all remaining frames. | |||
==Arctan Straining Proof== | |||
The displacement vector after <math>T</math> frames is | |||
<math>\mathbf{R} = (x_T - x_0)\mathbf{\hat{x}} + (z_T - z_0)\mathbf{\hat{z}}</math>, | |||
while the unit vector along the angle <math>\omega</math> is | |||
<math>\mathbf{\hat{n}} = \sin(\omega)\mathbf{\hat{x}} + \cos(\omega)\mathbf{\hat{z}}</math>. | |||
The distance we move along a target angle <math>\omega</math> over <math>T</math> frames is then | |||
<math> S = \mathbf{R} \cdot \mathbf{\hat{n}} = \langle S\rangle + \sum_{t=1}^T S_t, </math> | |||
where | |||
<math> \langle S \rangle = \left(v_0 T - \frac{DT(T+1)}{2}\right)\cos(\omega), </math> | |||
is due to our initial velocity and drag, while | |||
<math> S_t = 10\sin(\phi_t)\sin(\omega) + 1.5(T+1-t)\cos(\phi_t)\cos(\omega), </math> | |||
is the effective contribution from straining on frame <math>t</math>. | |||
Thanks to this separation, we can maximize the total distance <math>S</math> by individually maximizing each contribution <math>S_t</math> as a function of <math>\phi_t</math>: | |||
<math> \frac{d S_t}{d \phi_t} = 10\cos(\phi_t)\sin(\omega) - 1.5(T+1-t)\sin(\phi_t)\cos(\omega) = 0, </math> | |||
and finally we find | |||
<math> \tan(\phi_t) = \frac{10\tan(\omega)}{1.5(T+1-t)}, </math> | |||
or, rotating the coordinate system back to allow for general facing angles <math>\theta</math>, | |||
<math> \tan(\phi_t - \theta) = \frac{10\tan(\omega - \theta)}{1.5(T+1-t)}. </math> | |||
Since <math>\tan(x) = \tan(x\pm180^\circ)</math>, this equation has two solutions for <math>\phi_t</math> which are given above. | |||
== Iwerlipse Equations == | |||
By writing <math>\sin(\phi_t)</math> and <math>\cos(\phi_t)</math> in terms of <math>\tan(\phi_t)</math>, and using the optimal straining relation, we obtain exact expressions for the boundary of the Iwerlipse after <math>T</math> frames: | |||
<div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | |||
<math> \begin{aligned} x_T - x_0 &= \pm10 \sum_{t=1}^T \frac{1}{\sqrt{1+\beta^2 t^2}},\\ z_T - \langle z \rangle &= \pm1.5 \beta \sum_{t=1}^T \frac{t^2}{\sqrt{1+\beta^2 t^2}}, \end{aligned} </math> | |||
</div> | |||
where | |||
<math>\beta = \frac{1.5}{10}\tan(\omega),</math> | |||
and | |||
<math>\langle z \rangle = z_0 + v_0 T - \frac{DT(T+1)}{2}</math>. | |||
We can restrict <math>0 < \omega < 90^\circ</math>, with the four combinations of plus and minus signs giving the remaining quadrants. | |||
The Iwerlipse's half-width is <math>x_\mathrm{max} = 10T</math>, while its half-height is <math>z_\mathrm{max} = 3T(T+1)/4</math>. | |||
=== Approximations === | |||
If <math>T</math> is large, the exact expressions involve large summation terms, so it may be useful to have approximate expressions that are easier to compute. | |||
By replacing the summations from <math>t=1</math> to <math>t=T</math> with an integral from <math>t=1/2</math> to <math>t=T+1/2</math> (essentially performing the midpoint rule of numerical integration in reverse), we obtain | |||
<div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | |||
<math> \begin{aligned} x_T - x_0 &= \pm \frac{10}{\beta} \left[\operatorname{arsinh}(\beta t)\right]^{T+1/2}_{1/2},\\ z_T - \langle z \rangle &= \pm \frac{3}{4\beta^2} \left[\beta t\sqrt{1+\beta^2 t^2} - \operatorname{arsinh}(\beta t)\right]^{T+1/2}_{1/2}, \end{aligned} </math> | |||
</div> | |||
with the notation <math>[F(t)]_{t_1}^{t_2} = F(t_2) - F(t_1)</math>. | |||
This approximation converges to the true result very quickly: | |||
even for <math>T=2</math>, the RMS error (normalized by <math>x_\mathrm{max}</math> and <math>z_\mathrm{max}</math>) is <math>4.3\times10^{-3}</math>, | |||
while for <math>T>6</math> it is less than <math>10^{-3}</math>. | |||
Similar expressions obtained using the Euler–Maclaurin formula converge more slowly, even with first-order correction terms. | |||
A simpler but less accurate approximation is obtained by fitting the Iwerlipse to the generalized superellipse: | |||
<div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | |||
<math> \left(\frac{x_T - x_0}{x_\mathrm{max}}\right)^{m(T)} + \left(\frac{z_T - \langle z \rangle}{x_\mathrm{max}}\right)^{n(T)} = 1. </math> | |||
</div> | |||
The optimal exponents <math>m(T)</math> and <math>n(T)</math> have been found up to <math>T=150</math> (5 seconds), and can be obtained from a lookup table<ref>[https://drive.google.com/file/d/1xDmgHz878qiAS1ZF1Y5M0M1eiZUdZRSl/view?usp=sharing Showing Iwer's proof and deriving the Iwerlipse expressions.]</ref>. | |||
Unlike the integral approximation, this expression never converges to the exact result — there is always some small error. | |||
== Quarterstep Penalty == | |||
If <math>q \in {0,1,2,3}</math> quartersteps are lost on the final frame, | |||
the forward velocity gained on frame <math>t</math> no longer accumulates forward distance over <math>T+1-t</math> frames, | |||
but instead over <math>T - q/4 + 1 - t</math> frames. | |||
The optimal straining relation becomes: | |||
<div style="background:#f9f9f9; border-left:3px solid #bbb; padding:0.4em 0.8em; margin:1em 0;"> | |||
<math> \tan(\phi_{t'}) = \begin{cases} \dfrac{10\tan(\omega)}{1.5(T - q/4 + 1 - t)}, & \text{if } t < T,\\[10pt] \dfrac{10\tan(\omega)}{1.5}, & \text{if } t = T. \end{cases} </math> | |||
</div> | |||
The optimal straining angle for the final frame is not affected, since in this case the ellipse shrinks in both directions rather than just vertically, i.e. a factor <math>1-q/4</math> cancels in the numerator and denominator. | |||
== History == | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">2 July 2017</div> | |||
Plush discovers that during a dive recover, one can gain greater distance along an angle different from Mario's facing angle by “flinging” the control stick through different angles during the trajectory, rather than holding it at a constant angle. | |||
Pannenkoek qualitatively explains this phenomenon that would later be known as ''arctan straining'': | |||
<blockquote style="font-style: italic;"> | |||
I think you're supposed to hold forward-ish for most of it, then sideways at the end. Because sideways movement doesn't depend on your speed. So 5 frames of sideways holding at the start of the DR is equivalent to the 5 frames at the end. But forward distance depends on your hspeed. So let's say you start with some hspeed. If you go sideways then forwards, then you'll lose that hspeed. But if you go forward then sideways, then you'll take advantage of your starting hspeed. The best inputs would probably mix sideways and forwards somewhat. | |||
<br /> — <b>Pannenkoek2012</b> | |||
</blockquote> | |||
Peter Fedak shares the correct velocity update equations, and the three of them begin to consider what the mathematically optimal inputs are. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">3 September 2017</div> | |||
Iwer Sonsch independently rediscovers the velocity update equations and realises that by facing along the hypotenuse of the forward velocity and sideways speed — a trick known in other speedrunning communities as ''vectoring'' — he can gain greater distance in a single frame. | |||
He wonders how this would look over multiple frames, restarting the discussion of optimal straining. | |||
However, there is no quantitative progress until it becomes relevant to the A Button Challenge the following year. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">18 March 2018</div> | |||
The “Blast to the Stone Pillar” star in JRB is collected in 0 A presses for the first time, after Tyler Kehne figures out how to use conserved speed to get from the nearby pillar to the star platform. | |||
The community turns their attention to whether the “Treasure of the Ocean Cave” star can be collected in a similar way, again reviving the optimal straining question, as people including Iwer, bad_boot, and DeRockProject begin attempting to make the most of the limited speed they have available. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">16 April 2018</div> | |||
Iwer states the optimal straining equation for the first time in the following form: | |||
<math>\phi_{t'} - \theta = \operatorname{arccot}(0.15\,r\,t')</math> | |||
This is equivalent to our expression above, since <math>\operatorname{arccot}(x) = \arctan(1/x)</math>, | |||
with, <math>r = 1/\tan(\omega)</math>, and, <math>t' = T + 1 - t</math>. | |||
(If using this expression, we need to add 180° if the target angle is to the right of Mario, since <math>\operatorname{arccot}</math> only gives results between 0° and 180°.) | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">23 June 2018</div> | |||
Pannenkoek posts an idea for collecting the “Scale the Mountain” star in TTM via a dive recover. | |||
To find out whether it was possible, Iwer, Grassdigger, Jane, bad_boot, and DeRockProject work to plot all of Mario’s possible positions while air straining. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">20 August 2018</div> | |||
Iwer discovers the exact equations describing Mario's possible positions after <math>T</math> frames. Grassdigger and DeRockProject then show that the total shape can be well approximated by a generalised superellipse. | |||
Pannenkoek proposes calling it the ''Iwerlipse''. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">3 October 2019</div> | |||
Silverstrawb provides an alternative proof<ref>[https://drive.google.com/file/d/1df97glqVn-cXEUmP15vNxgQtwa8jJK2w/view?usp=sharing Showing Silverstrawb's proof.]</ref> of the optimal straining relation by converting the discrete update equations into the continuous differential equations | |||
<math>\begin{align} | |||
\dot{x} &= 10 \sin(\phi(t)),\\ | |||
\ddot{z} &= 1.5 \cos(\phi(t)) - D, | |||
\end{align}</math> | |||
and using the calculus of variations. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">29 July 2020</div> | |||
Krithalith independently rediscovers Iwer’s original proof and extends it to include quartersteps. | |||
<div style="font-size:120%; font-weight:bold; margin-top:1em;">27 November 2021</div> | |||
sm64expert adds arctan straining to MKDasher’s input direction LUA program, making it accessible to everyone for the first time. | |||
==See Also== | ==See Also== | ||
[[Straining]] | [[Straining]] | ||
==References== | ==References== | ||
{{#ev:youtube|_yx0eutBwII}} | |||
<references /> | |||
[[Category:Mechanics]] | [[Category:Mechanics]] | ||
edits