I'm coding a collision system for my 2D game engine in Java but I'm having problems with obtaining certain values. Lets say I have a rectangle and want to inscribe it into a grid. I want to list every grid cell which collide with the rectangle. As of rectangle what I know is its width, height, center point (x, y), angle in radians. As of cell, the coordinates of each cell are basically (n * size, m * size) where n, m = -2, -1, 0, 1, 2... (like in the image). I've been trying to find a fast solution for a long time but with no luck. I have also created a reference image for you to better understand my problem. The pink cells are the ones I want. I hope there's someone who had a similar problem and is willing to help me out :) Best of luck in your projects.
Asked
Active
Viewed 79 times
0

user2891047
- 15
- 5
-
2You might like to have a look at [this example](https://stackoverflow.com/questions/20927189/detecting-collision-of-two-sprites-that-can-rotate/20928531#20928531) – MadProgrammer Dec 03 '19 at 23:31
-
@MadProgrammer thank you, that's a really nice example. I might just simplify the detection. – user2891047 Dec 04 '19 at 00:02
-
That rectangle is not inscribed in the grid. – LowKeyEnergy Dec 04 '19 at 03:01
-
2You might also want to look into polygon rasterization / scanline conversion. – Nico Schertler Dec 04 '19 at 03:14
-
@LowKeyEnergy Sorry, I don't really know how to better write it in English. – user2891047 Dec 08 '19 at 10:59