algorithm - How do I determine whether angle A or B is closer to angle C? -


i want calculate whether angle or b closer angle c. i'm sure easy way angles return 0 @ 360 , vice versa confusing me how i'm supposed compare them.

right i'm doing this, wrong:

    similarity1 := degree - targetangle1     if (similarity1 > 360){         similarty1 := 360 - similarity1     }     similarity2 := degree - targetangle2     if (similarity2 > 360){         similarty2 := 360 - similarity2     }     if (similarity1 < similarity2){         degree := similarity1     } else {         degree := similarity2     } 

the answer must simple reason problem has me confused.

if work numbers in range of -180 180, can compare absolute value see less.

to numbers -180 180 range, must recognize adding or subtracting 360 angle doesn't change @ all.

similarity1 := degree - targetangle1 if (similarity1 > 180){     similarty1 := similarity1 - 360 } else if (similarity1 < -180){     similarity1 := similarity1 + 360 } similarity2 := degree - targetangle2 if (similarity2 > 180){     similarty2 := similarity2 - 360 } else if (similarity2 < -180){     similarity2 := similarity2 + 360 } if (abs(similarity1) <= abs(similarity2)){     degree := similarity1 } else {     degree := similarity2 } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -