November 24, 2005

Collision Detection

Posted in Algorithms at 2:50 pm by Scott Sehlhorst

We’ve moved to tynerblain.com/blog – this page is now here

Advertisements

1 Comment »

  1. Richard Krog said,

    I came across a problem just like the overlapping rectangles, but with only one dimention — time. “Do date ranges overlap?” We came up with:

    Overlap = A.start before B.end && B.start before A.end

    Likewise, you can remove the negative logic with the following:

    1. the right edge of A is to the *RIGHT* of the left edge of B
    2. the left edge of A is to the *LEFT* of the right edge of B
    3. the bottom of A is *BELOW* the top of B
    4. the top of A is *ABOVE* the bottom of B

    IF (1 && 2 && 3 && 4) THEN collision == TRUE;

    Both solutions are fail-fast, so the change is mostly semantic.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: