As written, all of these methods calculate the aspect ratio (x
/y), but bank_slopes will return (y / x) to be compatible
with link[ggplot2]{coord_fixed()}.
Median Absolute Slopes Banking
Let the aspect ratio be \(\alpha = \frac{w}{h}\)
then the median absolute slop banking is the
\(\alpha\) such that,
$$
median \left| \frac{s_i}{\alpha} \right| = 1
$$
Let \(R_z = z_{max} - z_{min}\) for \(z = x, y\),
and \(M = median \| s_i \|\). Then,
$$
\alpha = M \frac{R_x}{R_y}
$$
Average Absolute Slope Banking
Let the aspect ratio be \(\alpha = \frac{w}{h}\).
then the mean absolute slope banking is the
\(\alpha\) such that,
$$
mean \left| \frac{s_i}{\alpha} \right| = 1
$$
Average Absolute Orientation Banking
Rather than averaging the slopes themselves, this method averages the
orientation (angle) of each segment, since perceived slope
differences are more closely related to angle than to the raw ratio
\(dy/dx\). Let \(s'_i = s_i R_x / R_y\)
be the range-normalized slopes. Then \(\alpha\) is chosen such
that,
$$
mean \left| \arctan \left( \frac{s'_i}{\alpha} \right) \right| = \frac{\pi}{4}
$$
This has no closed-form solution and is found numerically with
uniroot.
Weighted Average Absolute Slope Banking
Identical to Average Absolute Slope Banking, except each segment's
contribution is weighted by its horizontal run, \(dx_i\), so
that segments spanning more horizontal (screen) space are weighted more
heavily than segments that happen to be sampled more densely in
\(x\). Using \(s'_i\) as above,
$$
\alpha = \frac{\sum_i dx_i \left| s'_i \right|}{\sum_i dx_i}
$$
Heer and Agrawala (2006) also discuss multi-scale (global and local)
orientation resolution, which extend these single-scale methods by
aggregating slopes computed at multiple scales rather than only between
adjacent points. These are not implemented here. In general, the
median, average, or average-orientation absolute slope methods will
produce reasonable results without requiring this additional
complexity.