0

I have three random points, $O$, $A$, $B$, with these I can get angles $\alpha$ and $\beta$

How can I get the angle $C$, or better, directional vector of c which will be evenly in the middle, between the other two angles. Keep in mind that the angles might be of any value.

This old answer almost gets me were I need to be, but how can I change the final formula presented in the answer ($g = \text{arctan}\,(2 \tan r)$) to work with non-right triangles?

I have found lots of results searching for this, but they don't seem to work in my case.

It looks like a good solution, but I don't know enough about trig to determine the part to change in the final formula to make it not right triangle dependant

![quick mockup](https://i.stack.imgur.com/ttg7p.png

  • 2
    It would be a lot easier to understand what you mean, if there was a good picture of the situation ... – Matti P. Feb 17 '20 at 08:15
  • Matti- There is actually a good diagram in the answer in the link in OP’s question – Adam Rubinson Feb 17 '20 at 08:17
  • 2
    Actually, OP- can you please draw a sketch of what you mean. It’s not clear what you mean by middle angle? – Adam Rubinson Feb 17 '20 at 08:20
  • @AdamRubinson Yes, good, and also about what is meant by "non-right triangles" in this case? – Matti P. Feb 17 '20 at 08:24
  • The angle between the other two. – SimpleRookie Feb 17 '20 at 15:05
  • Non right, unlike the liked post, I don't want to assume one angle is 90 degrees. – SimpleRookie Feb 17 '20 at 15:06
  • Using the diagram in the linked post. I still want to find B or g, just without the assumed 90 degree angle. – SimpleRookie Feb 17 '20 at 15:09
  • Is anyone understanding yet? – SimpleRookie Feb 17 '20 at 21:35
  • The way you have asked the question is self-contradictory. On the one hand you say you want an angle "evenly in the middle, between the other two angles." By definition this is an angle bisector. But you point to another question that asked for the angle of a median of a triangle, which bisects a side of a triangle, and in general is not an angle bisector. So maybe you want to bisect a line segment and not an angle? But then your own picture doesn't show any line segments that the line toward $C$ can bisect. – David K Feb 18 '20 at 01:09
  • So, for example, if the line from $O$ to $A$ is at an angle of $70$ degrees and the line from $O$ to $B$ is at $10$ degrees, is $40$ degrees the correct answer or not? (Note that according to the linked question, $40$ degrees is a wrong answer.) – David K Feb 18 '20 at 01:14
  • In my head the answer should be 40. If that is not what the other answer and question was relating too. I apologise for the confusion. – SimpleRookie Feb 18 '20 at 01:26

2 Answers2

1

You can use simple vector addition. Say $$\hat a=\frac{\vec{OA}}{|\vec{OA}|}\\\hat b=\frac{\vec{OB}}{|\vec{OB}|}$$ Since $|\hat a|=|\hat b|=1$, $\hat c=\hat a+\hat b$ points along the bisector of $\angle OAB$

Andrei
  • 37,370
  • Wouldn't this result in a zero if the angles are 180 degrees from each other? – SimpleRookie Feb 17 '20 at 21:53
  • 1
    Correct. But then the bisector does not make sense. Let's suppose $\hat a$ points to the left and $\hat b$ points to the right. Then any vector $c$ in the plane perpendicular to the horizontal axis is going to make an angle of $90^\circ$ with both vectors. Which one would you choose as the vector along the bisector? Even if you are defining the plane of the image, it can point either up or down. You would need to deal with that case separately – Andrei Feb 17 '20 at 22:02
0

The vector addition is a nice solution, but if you care about algorithmic complexity the square roots (in the norm) and divisions are not ideal.

Using your nomenclature of known angles $\alpha$, $\beta$ and unknown angle $c$, and assuming all three angles are from the same reference (eg. the x-axis), it feels like it should be as simple and taking the average of $\alpha$ and $\beta$. But this fails in two ways:

  1. If the angles are not numerically within $360^\circ$ of each other, the average no longer works as an angle average.
  2. Sometimes the average points C in the opposite direction. In other words, sometimes the angle is in the middle of the reflex angle, not "between" A and B in the usual sense.

Counter-intuitively, the best way I found to solve robustly this is to introduce the difference operation as inspired by this answer. To wit:

  1. Find the difference $\delta = \beta - \alpha$.
  2. While $\delta > 180°$, subtract $360^\circ$.
  3. While $\delta < -180°$, add $360^\circ$.
  4. $c = \alpha + \delta / 2$

In steps 2 and 3 (of which only zero or one of which will take effect), both failures 1 and 2 are taken care of by performing a modulo operation, but also by making sure we only consider the "inner" angle. The last step miraculously takes care of direction of rotation.

Some examples:

  • $\alpha = 20°, \beta = -10° \implies \delta = -30° \implies c = 20° - 15° = 5°$
  • $\alpha = -10°, \beta = 20° \implies \delta = 30° \implies c = -10° + 15° = 5°$
  • $\alpha = 20^\circ, \beta = 350^\circ \implies \delta = 330^\circ, -30^\circ \implies c = 20^\circ - 15^\circ = 5^\circ$
  • $\alpha = 190^\circ, \beta = -190^\circ \implies \delta = -380^\circ, -20^\circ \implies c = 190^\circ - 10^\circ = 180^\circ$
  • $\alpha = -80^\circ, \beta = 360^\circ+260^\circ \implies \delta = 700^\circ, 340^\circ, -20^\circ \implies c = -80^\circ - 10^\circ = -90^\circ$

Addendum: I actually devised this algorithm to find the angle of the "apex" of a vertex. That is, given a vector heading into a vertex and a vector heading out, what is the angle of the vector halfway around the vertex? So for me, direction was important, not inner/outer. But they turn out to be equivalent!

TShiong
  • 1,257