question: private void calculateIntersectPoints ( ) { intersectPoints . clear ( ) ; if ( center . x - menuBounds . left < expandedRadius ) { int dy = ( int ) Math . sqrt ( Math . pow ( expandedRadius , 2 ) - Math . pow ( center . x - menuBounds . left , 2 ) ) ; if ( center . y - dy > menuBounds . top ) { intersectPoints . add ( new Point ( menuBounds . left , center . y - dy ) ) ; } if ( center . y + dy < menuBounds . bottom ) { intersectPoints . add ( new Point ( menuBounds . left , center . y + dy ) ) ; } } if ( center . y - menuBounds . top < expandedRadius ) { int dx = ( int ) Math . sqrt ( Math . pow ( expandedRadius , 2 ) - Math . pow ( center . y - menuBounds . top , 2 ) ) ; if ( center . x + dx < menuBounds . right ) { intersectPoints . add ( new Point ( center . x + dx , menuBounds . top ) ) ; } if ( center . x - dx > menuBounds . left ) { intersectPoints . add ( new Point ( center . x - dx , menuBounds . top ) ) ; } } if ( menuBounds . right - center . x < expandedRadius ) { int dy = ( int ) Math . sqrt ( Math . pow ( expandedRadius , 2 ) - Math . pow ( menuBounds . right - center . x , 2 ) ) ; if ( center . y - dy > menuBounds . top ) { intersectPoints . add ( new Point ( menuBounds . right , center . y - dy ) ) ; } if ( center . y + dy < menuBounds . bottom ) { intersectPoints . add ( new Point ( menuBounds . right , center . y + dy ) ) ; } } if ( menuBounds . bottom - center . y < expandedRadius ) { int dx = ( int ) Math . sqrt ( Math . pow ( expandedRadius , 2 ) - Math . pow ( menuBounds . bottom - center . y , 2 ) ) ; if ( center . x + dx < menuBounds . right ) { intersectPoints . add ( new Point ( center . x + dx , menuBounds . bottom ) ) ; } if ( center . x - dx > menuBounds . left ) { intersectPoints . add ( new Point ( center . x - dx , menuBounds . bottom ) ) ; } } int size = intersectPoints . size ( ) ; if ( size == 0 ) { fromAngle = 0 ; toAngle = 360 ; return ; } int indexA = size - 1 ; double maxAngle = arcAngle ( center , intersectPoints . get ( 0 ) , intersectPoints . get ( indexA ) , menuBounds , expandedRadius ) ; for ( int i = 0 ; i < size - 1 ; i ++ ) { Point a = intersectPoints . get ( i ) ; Point b = intersectPoints . get ( i + 1 ) ; double angle = arcAngle ( center , a , b , menuBounds , expandedRadius ) ; Point midnormalPoint = findMidnormalPoint ( center , a , b , menuBounds , expandedRadius ) ; int pointerIndex = i ; int endIndex = indexA + 1 ; if ( ! isClockwise ( center , a , midnormalPoint ) ) { int tmpIndex = pointerIndex ; pointerIndex = endIndex ; endIndex = tmpIndex ; } if ( pointerIndex == intersectPoints . size ( ) - 1 ) { pointerIndex = 0 ; } else { pointerIndex ++ ; } if ( pointerIndex == endIndex && angle > maxAngle ) { indexA = i ; maxAngle = angle ; } } Point a = intersectPoints . get ( indexA ) ; Point b = intersectPoints . get ( indexA + 1 >= size ? 0 : indexA + 1 ) ; Point midnormalPoint = findMidnormalPoint ( center , a , b , menuBounds , expandedRadius ) ; Point x = new Point ( menuBounds . right , center . y ) ; if ( ! isClockwise ( center , a , midnormalPoint ) ) { Point tmp = a ; a = b ; b = tmp ; } fromAngle = pointAngleOnCircle ( center , a , x ) ; toAngle = pointAngleOnCircle ( center , b , x ) ; toAngle = toAngle <= fromAngle ? 360 + toAngle : toAngle ; }
target:  find all intersect points, and calculate menu items display area;