While making an interactive recreation of a schematic rail map, I discovered that the angle of the diagonal lines are not exactly 45 degrees but have a 1.4 degrees additional offset.
I'm writing a small piece of drawing software in which all lines should snap to certain angles. Snapping to exactly 45 degrees is easy enough:
$$snapped = (\approx bearing \div 45) \cdot 45$$
However, my problem lies in writing a function that performs a mapping as follows:
- $45 \Rightarrow 46.4$
- $-45 \Rightarrow -46.4$
- $135 \Rightarrow 133.6$
- $-135 \Rightarrow -133.6$
Is there a 'clean' calculation for the above mapping without explicitly defining the inputs and outputs?
The issue occurs because your $x$ and $y$ units on the map have slightly different lengths. If they would have the same length, $$\tan\alpha=\frac{\Delta y}{\Delta x}$$ In your case, $y$ is longer by about $5\%$. So $$\tan\alpha'=\frac{1.05\Delta y}{\Delta x}$$ For computer programs is nice if you use $\mathrm{arctan2}$ function. See wikipedia. So the answer would be $$\alpha'=\mathrm{arctan2}(1.05\sin\alpha,\cos\alpha)$$ Depending on the implementation, you might need to transform input to radians and output to degrees. So in Python, I would have a function like