How to calculate an angle with a specific additional offset from 45 degrees?

335 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

import numpy as np 
def ang(inp):
    si=np.sin(np.radians(inp))
    ci=np.cos(np.radians(inp))
    return np.degrees(np.arctan2(1.05*si,ci))
0
On

The line $y = x$ is modified to have more slope by a factor of $ \tan{46.4^\circ} $

and the line $y = -x$ is modified to have more negative slope by the same factor.

Therefore, $ \phi = \text{Atan2} \left( \cos \theta, \tan(46.4^\circ) \sin \theta \right) $

where $\phi$ is the output angle and $\theta $ is in the input angle.