I'm writing a collision algorithm based on the Separating Axis Theorem that works like so for each side:

- Gets the separating axis of the side
- Measures the object's width on that axis and places the width on the axis.
- Measures/places width for object that is being collision-tested.
- Draws two (unrotated) rectangles, herein referred to as axial rectangles, on the widths, using them as diagonals.
- Runs the SAT on the two axial rectangles, which are x/y aligned unlike the objects being tested,. If they overlap, the tested objects overlap on the given axis. If they overlap on 2 or more axes, they intersect.

My questions are these:
1. Is this the most efficient way to do it? Can you test the overlap of two line segments that doesn't correspond to the system's coordinates? IE, not both on an X or Y axis?

2. Given the two shapes I'm drawing, how do I move both axial rectangles so that their diagonals (the widths) are actually collinear on the axis? I can't figure out a way to do that.

I'm still trying to figure this out. I'm fairly certain that dot products of the vectors involved are relevant in some way, but I can't figure out how to use them for testing.

Sounds like there is a lot of math involved. If you refer to a theorem, you should link it:


Is this a math problem or a problem with the implementation of the math in Java (i.e. do you understand the theorem and know how to use it successfully, but you just can't implement it in Java)? If it's a question on the theorem itself, a math forum might be better. If it's a question on implementation in Java, you should post the relevant code.

What kind of objects are we talking about? If we're talking about fairly simple objects like circles, rectangles, triangles, etc., there might be easier methods, but there'll still be a considerable amount of math involved.

This article has been dead for over six months. Start a new discussion instead.