Given four points in the plane, A,B,X,Y
, I wish to determine which of the following two angles is smaller ∢ABX
or ∢ABY
.
The angle ∢ABX
is defined as the angle of BX
, when AB
is translated to lie on the open segment (-∞,0]
. Intuitively when saying ∢ABX
I mean the angle you get when you turn left after visiting vertex B
.
I'd rather not use cos
or sqrt
, in order to preserve accuracy, and to minimize performance (the code would run on an embedded system).
In the case where A=(-1,0),B=(0,0)
, I can compare the two angles ∢ABX
and ∢ABY
, by calculating the dot product of the vectors X,Y
, and watch its sign.
What I can do in this case is:
- Determine whether or not
ABX
turns right or left - If
ABX
turns left check whether or notY
andA
are on the same side of the line on segmentBX
. If they are -∢ABX
is a smaller thanABY
. - If
ABX
turns right, thenY
andA
on the same side ofBX
means that∢ABX
is larger than∢ABY
.
But this seems too complicated to me.
Any simpler approach?