• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Safe way to get the middle of 2 angles value?

Status
Not open for further replies.
Level 13
Joined
Mar 29, 2012
Messages
542
If:
angle1 = 90
angle2 = 180
midAngle = 135 <-- Okay, no problem.

If:
angle1 = 360
angle2 = 90
midAngle = 225 (wrong: not a middle between 360 and 90, toward south) <-- Which must supposedly be 45 (toward north)

Formula used:
midAngle = angle1 + ( (angle2 - angle1) / 2 )

Any suggestion?
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,220
Err, what?

It gives the middle angle, just not the one you might expect.

f805c658e9f3a5a827d3f0adacd56eaf.png


There are two answers, in this image 45 is the closest middle, but the one at the opposite end is also equally in the middle.

Either that or I am retarded.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
As pointed out above...

There are technically 2 middle angles due to the circular nature of angles. Unless the 2 angles are exactly 180 degrees apart then one of the middle angles will be closer to the angles than the other middle angle.

A stupid way of finding the angle...
midAngle1 = (angle1 + angle2) /2
midAngle2 = midAngle1 + 180 degrees

One can use modulus to restrict the range to between 0 and 360 degrees if one wants.

To find which mid angle is the closest to the original angles...

Cosine(midAngle1 - angle1) > Cosine(midAngle2 - angle1)
If true then midAngle1 is closer, otherwise midAngle2 is closer. Note that there will be a bias towards midAngle1 in the case that angle1 and angle2 are exactly 180 degrees apart, however this is needed to solve the problem of both mid angles being exactly 90 degrees from both angle1 and angle2.
 
Status
Not open for further replies.
Top