Detect rotated rectangle collision
Posted
by
handyface
on Game Development
See other posts from Game Development
or by handyface
Published on 2013-10-15T07:02:38Z
Indexed on
2013/10/17
22:22 UTC
Read the original article
Hit count: 168
collision-detection
|algorithm
I'm trying to implement a script that detects whether two rotated rectangles collide for my game. I used the method explained in the following article for my implementation in Google Dart.
2D Rotated Rectangle Collision
I tried to implement this code into my game. Basically from what I understood was that I have two rectangles, these two rectangles can produce four axis (two per rectangle) by subtracting adjacent corner coordinates.
Then all the corners from both rectangles need to be projected onto each axis, then multiplying the coordinates of the projection by the axis coordinates (point.x*axis.x+point.y*axis.y
) to make a scalar value and checking whether the range of both the rectangle's projections overlap. When all the axis have overlapping projections, there's a collision.
First of all, I'm wondering whether my comprehension about this algorithm is correct. If so I'd like to get some pointers in where my implementation (written in Dart, which is very readable for people comfortable with C-syntax) goes wrong.
Thanks!
© Game Development or respective owner