Android Angle Convert difference(final float from, final float to)

Here you can find the source of difference(final float from, final float to)

Description

Return the angle to turn of to go from an angle to the other

License

Apache License

Parameter

Parameter Description
from the origin angle in degrees
to the target angle in degrees

Return

a value in degrees, in the [-180, 180[ range

Declaration

public static float difference(final float from, final float to) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  w  w  . j av  a  2 s .  c  o  m*/
     * 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;
    }
}

Related

  1. constrainAngle(float degree)
  2. normalize(final float angle)