Java tutorial
//package com.java2s; public class Main { public static final double TWO_PI_RADS = Math.PI * 2.0; /** * @param angle * @return the angle between -pi and pi */ public static double nomalizeAngleRadsPi(double angle) { double ret = angle; while (ret > Math.PI) ret -= TWO_PI_RADS; while (ret < -Math.PI) ret += TWO_PI_RADS; return ret; } }