blob: fdd9a9dc96bcdd2dd379fe98bfd933d7f7c7a57b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package cgeo.geocaching.utils;
public final class AngleUtils {
private AngleUtils() {
// Do not instantiate
}
/**
* Return the angle to turn of to go from an angle to the other
*
* @param from
* the origin angle in degrees
* @param to
* the target angle in degrees
* @return a value in degrees, in the [-180, 180[ range
*/
public static float difference(final float from, final float to) {
return normalize(to - from + 180) - 180;
}
/**
* Normalize an angle so that it belongs to the [0, 360[ range.
* @param angle the angle in degrees
* @return the same angle in the [0, 360[ range
*/
public static float normalize(final float angle) {
return (angle >= 0 ? angle : (360 - ((-angle) % 360))) % 360;
}
}
|