1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| struct Point_F { double x; double y; };
struct RECT { double left; double top; double right; double bottom; };
bool AABBPointInside(const Point_F& V, const RECT& RECT) { return (V.x > RECT.left && V.x < RECT.right && V.y > RECT.top && V.y < RECT.bottom); }
bool AABBRectInside(const RECT& rect1, const RECT& rect2) { return (rect2.left >= rect1.left && rect2.right <= rect1.right && rect2.top >= rect1.top && rect2.bottom <= rect1.bottom); }
bool AABBRectOverlap(const RECT& rect1, const RECT& rect2) { return (rect1.right < rect2.left || rect1.left > rect2.right || rect1.bottom < rect2.top || rect1.top > rect2.bottom) ? false : true; }
bool AABBRectCircleOverlap(double rectCenterX, double rectCenterY, double rectWidth, double rectHeight, double angle, double circleX, double circleY, double circleRadius) { double vectorX = circleX - rectCenterX; double vectorY = circleY - rectCenterY; double radians = angle * M_PI / 180.0; double x = vectorX * cos(radians) + vectorY * sin(radians); double y = vectorY * cos(radians) - vectorX * sin(radians); double halfWidth = rectWidth * 0.5; double halfHeight = rectHeight * 0.5; if (x - circleRadius < halfWidth && x + circleRadius > -halfWidth) { if (y - circleRadius < halfHeight && y + circleRadius > -halfHeight) { if (x < -halfWidth && y < -halfHeight){ if (distance(x, y, -halfWidth, -halfHeight) >= circleRadius) { return true; } } else if (x < halfWidth && y < -halfHeight){ if (distance(x, y, halfWidth, -halfHeight) >= circleRadius) { return true; } } else if (x > halfWidth && y > halfHeight){ if (distance(x, y, halfWidth, halfHeight) >= circleRadius) { return true; } } else if (x < -halfWidth && y > halfHeight) { if (distance(x, y, -halfWidth, halfHeight) >= circleRadius) { return true; } } } return true; } return false; }
bool AABBPointInCircle(double pointX, double pointY, double circleCenterX, double circleCenterY, double circleRadius) { double dx = pointX - circleCenterX; double dy = pointY - circleCenterY; return sqrt(dx * dx + dy * dy) <= circleRadius; }
bool AABBCirclesIntersect(double circleCenterX1, double circleCenterY1, double circleRadius1, double circleCenterX2, double circleCenterY2, double circleRadius2) { double dx = circleCenterX1 - circleCenterX2; double dy = circleCenterY1 - circleCenterY2; return sqrt(dx * dx + dy * dy) <= circleRadius1 + circleRadius2; }
bool AABBPointInAnnulus(double x, double y, double circleCenterX, double circleCenterY, double circleRadius, double innerThickness, double outerThickness) { double dx = x - circleCenterX; double dy = y - circleCenterY; double dist = sqrt(dx * dx + dy * dy); return (dist <= circleRadius + outerThickness && dist >= circleRadius - innerThickness); }
bool AABBPointInEllipse(double centerX, double centerY, double radiusA, double radiusB, double x, double y) { double dx = centerX - x; double dy = centerY - y; return (dx * dx / (radiusA * radiusA) + dy * dy / (radiusB * radiusB)) <= 1; }
|