Quantcast
Channel: How to calculate distance between two rectangles? (Context: a game in Lua.) - Stack Overflow
Viewing all articles
Browse latest Browse all 11

How to calculate distance between two rectangles? (Context: a game in Lua.)

$
0
0

Given two rectangles with x, y, width, height in pixels and a rotation value in degrees -- how do I calculate the closest distance of their outlines toward each other?

Background: In a game written in Lua I'm randomly generating maps, but want to ensure certain rectangles aren't too close to each other -- this is needed because maps become unsolvable if the rectangles get into certain close-distance position, as a ball needs to pass between them. Speed isn't a huge issue as I don't have many rectangles and the map is just generated once per level. Previous links I found on StackOverflow are this and this

Many thanks in advance!


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles



Latest Images