Given any two angle values, find angle of incidence or difference

38 Views Asked by At

I want to find the angle of incidence or simply the difference between some ray and some surface, given their respective angles in some coordinate system. No need for further definition, it's just a question about angle differences.

As far as I can tell, the angles can have any values on the real number line (like -10000 or + 999999). (I can bring them in the [0,360] range or any other range, but that counts as 1 computational step, and at the end I want the computationally simplest process. So a computational process that would not require bringing both angles to a range first, but say, only bringing their difference to a range would be one step simpler)

I just want to know if they are rather parallel (angle between the two is close to zero, they almost go in the same direction) or rather perpendicular (almost 90° from one another). Therefore an answer that is either negative or greater than 90° has no usable meaning for me.

What is the simplest way to get there in all input situations ? I mean, with the least computation steps.

NB : Angle to normal ("angle of incidence" in physics) or the complement to 90° of that are all the same to me, since at the end I am guaranteed a result between 0 and 90° I can always take the complement to 90°.

Best I can muster so far :

  1. Take the difference between the angles
  2. Bring to [0,360]
  3. If larger than 90, take complement to 180. Else, finished.
  4. Take absolute value.
  5. Go to 3.

Actually you only need to go through 3. twice maximum, given 2.

Example :

enter image description here

Red is given as 350°. Green is given as -210° degrees. The expected result is 20°.

  1. Difference is -210-350 = -560°.
  2. Mod 360° : 160°
  3. Larger than 180° : take 180-160 = 20°.
  4. Take absolute value : 20° (unchanged).
  5. Go to 3.
  6. Smaller than 180° : finished.
1

There are 1 best solutions below

3
On

The easiest way to calculate the angle between two lines who can be described as vectors, is based on:

$$\overrightarrow{a} \cdot \overrightarrow{b} = ||\overrightarrow{a}|| \cdot ||\overrightarrow{b}|| \cdot \cos(\alpha)$$

Where $\alpha$ is the angle between $\overrightarrow{a}$ and $\overrightarrow{b}$.