I'm developing a model for the collision for two ships.
First, I have the angle that the first ship would be pointing if it was to directly point at the second ship. I'll call the angle between the two ships $\phi$.
Next, I have the measured angle of the first ship's trajectory, which I'll call $\theta$.
The problem is, I check if $\theta$ is greater or less than $45^{\circ}$ from $\phi$. This is fine if the $\phi$ is, say, $180^{\circ}$, and $\theta$ is, say, $170^{\circ}$. This is fine until I hit the problem of $0^{\circ}$. If $\phi$ is $10^{\circ}$, and $\theta$ is $357^{\circ}$, it would still be within that $45^{\circ}$ radius. However, it would not be detected.
What is an easy/simple way to solve it so that if $\phi = 10^{\circ}$ and $ \theta = 357^{\circ}$ would still be detected as within the $45^{\circ}$ radius?
double diff = min(abs(clrot - angle2), abs(abs(clrot - angle2) - 360)); if (diff < 45){– user2722083 Mar 29 '15 at 12:17clrotandangle2respectively). I just noticed that you can save oneabs:diff = min(abs(clrot-angle2), 360 - abs(clrot-angle2))becauseabs(clrot-angle2)will always be at most $360$ so $||\alpha_1 - \alpha_2| - 360| = 360 - |\alpha_1 -\alpha_2|$. – AlexR Mar 29 '15 at 12:19clrotis the rotation of the client (between 0 and 360),angle2is the angleclrotwould have to be pointing at for it to point directly to the other ship. – user2722083 Mar 29 '15 at 12:24