Here you can find the source of reduceAngle(double theta)
public static final double reduceAngle(double theta)
//package com.java2s; public class Main { public static final double PI = Math.PI; public static final double TWOPI = Math.PI * 2; public static final double HALF_PI = PI / 2; public static final double reduceAngle(double theta) { theta %= TWOPI;//from ww w. ja v a 2 s.co m if (Math.abs(theta) > PI) { theta = theta - TWOPI; } if (Math.abs(theta) > HALF_PI) { theta = PI - theta; } return theta; } }