# Separating axis Theorem rotation issue

This topic is 1728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

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.

(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!

Edited by nickyc95

##### Share on other sites

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();
}

[/source]

##### Share on other sites

@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

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

@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

##### Share on other sites

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! :)

##### Share on other sites

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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634086
• Total Posts
3015414
×