public static int octant(double dx,double dy){
  if (dx == 0.0 && dy == 0.0)   throw new IllegalArgumentException("Cannot compute the octant for point ( " + dx + ", "+ dy+ " )");
  double adx=Math.abs(dx);
  double ady=Math.abs(dy);
  if (dx >= 0) {
    if (dy >= 0) {
      if (adx >= ady)       return 0;
 else       return 1;
    }
 else {
      if (adx >= ady)       return 7;
 else       return 6;
    }
  }
 else {
    if (dy >= 0) {
      if (adx >= ady)       return 3;
 else       return 2;
    }
 else {
      if (adx >= ady)       return 4;
 else       return 5;
    }
  }
}

public static int octant ( double dx , double dy ) { if ( dx == 0.0 && dy == 0.0 ) throw new IllegalArgumentException ( "Cannot compute the octant for point ( " + dx + ", " + dy + " )" ) ; double adx = Math . abs ( dx ) ; double ady = Math . abs ( dy ) ; if ( dx >= 0 ) { if ( dy >= 0 ) { if ( adx >= ady ) return 0 ; else return 1 ; } else { if ( adx >= ady ) return 7 ; else return 6 ; } } else { if ( dy >= 0 ) { if ( adx >= ady ) return 3 ; else return 2 ; } else { if ( adx >= ady ) return 4 ; else return 5 ; } } }
returns the octant of a directed line segment ( specified as x and y displacements , which cannot both be 0 ) .
