Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static boolean rotatedRectangleVsCircle(GameObject rect, GameObject circle)
- {
- double rectCx = rect.currX + rect.width / 2, //Rectangle center x
- rectCy = rect.currY + rect.height / 2, //Rectangle center y
- cirX = circle.currX + circle.width / 2, //Circle center x
- cirY = circle.currY + circle.height/ 2, //Circle center y
- rot = rect.rotation, // The rotation of the rectangle, in degrees
- cx = Math.cos(rot) * (cirX - rectCx) - Math.sin(rot) * (cirY - rectCy) + rectCx,
- cy = Math.sin(rot) * (cirX - rectCx) + Math.cos(rot) * (cirY - rectCy) + rectCy,
- x,y;
- if (cx < rect.currX)
- x = rect.currX;
- else if (cx > rect.currX + rect.width)
- x = rect.currX + rect.width;
- else
- x = cx;
- if (cy < rect.currY)
- y = rect.currY;
- else if (cy > rect.currY + rect.height)
- y = rect.currY + rect.height;
- else
- y = cy;
- double distance = findDistance(cx, cy, x, y);
- if (distance < circle.width / 2)
- return true;
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement