public static double clampAngle(double angle){
  double newAngle=angle % 360;
  if (newAngle < 0)   newAngle=360 + newAngle;
  return newAngle;
}

public static double clampAngle ( double angle ) { double newAngle = angle % 360 ; if ( newAngle < 0 ) newAngle = 360 + newAngle ; return newAngle ; }
clamp an angle ( in degrees ) to 360 , and transform negative angles into their positive counterparts .
