Anyone have a simple algorithm for this? No need for rotation or anything. Just finding if a line segment made from two points intersects a square
Here's a way:
- sort the vertex points of the square by x-coord
- sort the endpoint of the line by x-coord
- calculate angle from the minX end of the line to each of the middle two (by x-coord) square vertices
- calculate angle of the line
- if the line's angle is within the possible angles, all you have to do is a length check, is maxX end of the line > minX vertex of the square
This will probably break if the square is directly facing the line, in that case I'd just special-case it by checking the first edge of the square.