Calculating yaw

Discussion in 'Spigot Plugin Development' started by Stijn_Jacobs, May 6, 2017.

  1. Hello,
    I need to calculate the yaw difference between 2 locations with yaw. The problem is that the yaw goes from -180 to 180. I've already tried a lots of calculations but they never work out. Example:

    Yaw 1: 135
    Yaw 2: -180

    The difference would be +45 ( -180 is next to 180 ).
     
  2. One way would be to bring all negative yaw values to 180-359 (by adding 360) and then substract one from the other:
    Code (Java):
    int yaw1Normalized = (yaw1 < 0) ? yaw1 + 360 : yaw1;
    int yaw2Normalized = (yaw2 < 0) ? yaw2 + 360 : yaw2;
    int angle = yaw2Normalized - yaw1Normalized;
     
    • Like Like x 2