Here you can find the source of angleDiff(double angle1, double angle2, boolean normalized)
public static double angleDiff(double angle1, double angle2, boolean normalized)
//package com.java2s; /*// w w w . ja v a 2 s. co m * Debrief - the Open Source Maritime Analysis Application * http://debrief.info * * (C) 2000-2014, PlanetMayo Ltd * * This library is free software; you can redistribute it and/or * modify it under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html) * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ public class Main { private static final double TWO_PI = 2 * Math.PI; public static double angleDiff(double angle1, double angle2, boolean normalized) { if (!normalized) { angle1 = normalizeAngle(angle1); angle2 = normalizeAngle(angle2); } return Math.min(Math.abs(angle1 - angle2), Math.min(Math.abs(angle1 - angle2 + TWO_PI), Math.abs(angle1 - angle2 - TWO_PI))); } /** * return angle from [0; 2*Math.PI) * @param angle * @return */ public static double normalizeAngle(double angle) { double minus = angle < 0 ? 2 : -2; while (angle < 0 || angle >= TWO_PI) { angle += minus * Math.PI; } return angle; } }