Java examples for 2D Graphics:Angle
Given an input angle in radians, return an equivalent angle constrained to lie in the range (-pi, pi].
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { double angle = 2.45678; System.out.println(constrainAngle(angle)); }// ww w . ja v a2s .c o m public static double PI = Math.PI; /** * Given an input angle in radians, return an equivalent angle constrained * to lie in the range (-pi, pi]. */ public static double constrainAngle(double angle) { while (angle > Math.PI) angle -= 2 * Math.PI; while (angle <= -Math.PI) angle += 2 * Math.PI; return angle; } }