Separating axis Theorem rotation issue

Started by
6 comments, last by Burnt_Fyr 9 years, 11 months ago

Hello there,

I am trying to get SAT working within my 2d game using Windows 8 and DirectX (DirectXTK).

However i have run into an issue which I cannot figure out.

(I have uploaded a video to youtube that demonstrates the issue)

When the boxes are AABB the collision works great, when i rotate the boxes the axis "flys" off and the boxes dont collide properly because of this.

YOUTUBE LINK :

(IGNORE THE WHITE BOXES TO THE LEFT OF THE SCREEN)

If anyone has any ideas about what could be causing this please let me know. Also if you would like to see the code, please post and tell me.

Thanks!

Advertisement

Can you post your code. Looks like the way you are calculating the axis is wrong.

If you look at the top it looks like the Axis is being projected on the the X plane.

This is how I calculate the Axis.

[source lang="csharp"]

for (int x = 0; x < Points.Count; x++)
{
Vector3 p1 = Points[x];
Vector3 p2 = Points[x + 1 == Points.Count ? 0 : x + 1];
Vector3 edge = p1 - p2;
var A = new Vector2(-edge.X, edge.Y);
A.Normalize();
Axis.Add(A);
}

[/source]

@nicky95

It's hard to tell exactly what goes wrong without seeing any code.

@CJThomas

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"

Cheers,

Mike


It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time

Just curious as I don't know and would like to - when I use dot product to project a vertex onto an axis in SAT, I use the fact that the axis vector is normalized to give me the distance along the axis as the simple result of the dot product. How do you retrieve this if the axis vector isn't normalized?

Is it just a case of dividing the result by the length of the axis vector? If so, you still need the length of the axis vector, which is the slow bit of normalization.

Hi Aardvajk. I don't actually calculate the distance, since it is not needed. If you want the distance, you need to solve the Pythagorean theorem, which means calling square root. It's getting late here in Europe so I won't go into a lengthy explanation on SAT, but here are some links you might find useful:

http://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf

Cheers,
Mike


@CJThomas



It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"

Thanks for the Tip. I have removed that line and it works fine


Hi Aardvajk. I don't actually calculate the distance, since it is not needed.

Oh of course, you can compare the squared distances to check for overlaps. Doh! :)

Thanks for the links.


It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time

Just curious as I don't know and would like to - when I use dot product to project a vertex onto an axis in SAT, I use the fact that the axis vector is normalized to give me the distance along the axis as the simple result of the dot product. How do you retrieve this if the axis vector isn't normalized?

Is it just a case of dividing the result by the length of the axis vector? If so, you still need the length of the axis vector, which is the slow bit of normalization.

Aardvark, your instincts are correct. The dot product gives: Dot(A,B) = |A||B|Cos(Theta), so ( Dot(A,B) ) / |B| gives the distance of A projected onto B, which simplifies to dot(a,b) when b is a unit length vector.

This topic is closed to new replies.

Advertisement