• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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:
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.
 
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.
Back
Top