• Create Account

## Separating axis Theorem rotation issue

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1nickyc95  Members

Posted 03 April 2014 - 09:03 AM

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, 03 April 2014 - 09:03 AM.

### #2CJThomas  Members

Posted 03 April 2014 - 04:39 PM

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.

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

}


### #3h4tt3n  Members

Posted 04 April 2014 - 01:23 AM

@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

### #4Aardvajk  Members

Posted 04 April 2014 - 11:33 AM

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.

### #5h4tt3n  Members

Posted 04 April 2014 - 03:30 PM

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

### #6CJThomas  Members

Posted 07 April 2014 - 06:35 PM

@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

### #7Aardvajk  Members

Posted 08 April 2014 - 01:05 AM

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!

### #8Burnt_Fyr  Members

Posted 26 April 2014 - 08:52 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.