Math question: How to compute the area of polygons

Dar Scott dsc at swcp.com
Wed Mar 19 12:43:01 EST 2003


On Wednesday, March 19, 2003, at 09:05 AM, Geoff Canyon wrote:

> But before you even do that, you should come up with a rough, simple 
> calculation that will tell you there is no collision, or that you need 
> to do the more exact test. So for example, if polygon A has no point 
> more than 30 pixels away from its loc, and polygon B has no point more 
> than 25 pixels away from its loc, then your first calculation would be 
> the distance between the loc of A and the loc of B; if it's more than 
> 55 pixels, there is no intersection. If it's less, then you do the 
> more exact calculation.

A rough test is a very good idea, especially if there are lots of 
objects that might collide.

An alternate rough test is the bounding rectangle overlap.

> If you're looking for collision detection, I think it would be faster 
> to check the line segments of polygon A against the line segments of 
> polygon B to see if any of them intersect. If they do, there's a 
> collision. There may be a faster way than that, but I think at least 
> that it would be faster than computing the areas.

Ah, I just mailed off the same idea.  There is a hole.  That is the 
case of one being completely inside the other.  I covered that in my 
mailing, but it may not be needed.

Dar Scott




More information about the use-livecode mailing list