Advertisement
Guest User

Untitled

a guest
Apr 4th, 2013
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. private static boolean rotatedRectangleVsCircle(GameObject rect, GameObject circle)
  2. {
  3.     double rectCx = rect.currX + rect.width / 2,    //Rectangle center x
  4.            rectCy = rect.currY + rect.height / 2,   //Rectangle center y
  5.            cirX = circle.currX + circle.width / 2//Circle center x
  6.            cirY = circle.currY + circle.height/ 2//Circle center y
  7.            rot = rect.rotation,                     // The rotation of the rectangle, in degrees
  8.            cx = Math.cos(rot) * (cirX - rectCx) - Math.sin(rot) * (cirY - rectCy) + rectCx,
  9.            cy = Math.sin(rot) * (cirX - rectCx) + Math.cos(rot) * (cirY - rectCy) + rectCy,
  10.            x,y;
  11.      
  12.     if (cx < rect.currX)
  13.         x = rect.currX;
  14.     else if (cx > rect.currX + rect.width)
  15.         x = rect.currX + rect.width;
  16.     else
  17.         x = cx;
  18.      
  19.     if (cy < rect.currY)
  20.         y = rect.currY;
  21.     else if (cy > rect.currY + rect.height)
  22.         y = rect.currY + rect.height;
  23.     else
  24.         y = cy;
  25.      
  26.     double distance = findDistance(cx, cy, x, y);
  27.     if (distance < circle.width / 2)
  28.         return true;
  29.     else
  30.         return false;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement