Page 1 of 1

Pythagoras theorem for colission detection between squares

Posted: Sat Jun 12, 2010 6:59 pm
by Zer0XoL
Well, this might be more of a math problem but still...
I recently found out that i could easily check the distance between two objects using pythagoras theorem :P, so i used it for colission detection, it works great for circles and that but, when for example i want to check the colission between walls i need to do it with squares, so i was wondering, does anyone have a thought for how i could use pythagoras theorem for colission detection between two squares?
my idea was doing it for each edge of the square and somehow compare the different distances, but i have no succes, it would be intresting thought if it worked because that would save a bit of energy and maby speed some things up. :P
forgive my spelling

Re: Pythagoras theorem for colission detection between squares

Posted: Sat Jun 12, 2010 10:49 pm
by Bullet Pulse
I think you would be better off using a normal square collision algorithm, or if you need pixel perfect, then use that.
If you're using trig, then there is usually a simpler way to do it. ;)

Search around the forum for the topics on collision and you'll find more help.

Re: Pythagoras theorem for colission detection between squares

Posted: Sat Jun 12, 2010 11:29 pm
by Bakkon
Uhh, by Pythagorean Theorem collision, do you mean "iff distance < radius1 + radius 2 they are colliding"? Yeah, you'd be better off using AABB for squares/rectangles.

Re: Pythagoras theorem for colission detection between squares

Posted: Sun Jun 13, 2010 7:01 am
by Zer0XoL
So you are saying i should use normal collision detection for squares? Yeah I probably should, but i want to see if its possible with this, and if so then i could probably use it with rotating squares too.
Im just interested in if something like this is possible, not for what i should use but tnx anyway :P

Re: Pythagoras theorem for colission detection between squares

Posted: Mon Jun 14, 2010 5:26 pm
by Ginto8
Zer0XoL wrote:So you are saying i should use normal collision detection for squares? Yeah I probably should, but i want to see if its possible with this, and if so then i could probably use it with rotating squares too.
Im just interested in if something like this is possible, not for what i should use but tnx anyway :P
It depends. Circular collision detection is a LOT less expensive than SAT for when things are far away. Using circular for an initial collision detection is perfect, because if you have a circle circumscribed around the rects and those circles aren't touching, there's NO way the rects can be touching. So for OBBs using circular collision for an initial check is very good. For AABBs, circular detection is just a waste of CPU.

Re: Pythagoras theorem for colission detection between squares

Posted: Mon Jun 14, 2010 9:17 pm
by avansc
If you want to to simple AABB rect collision you can make it about half as simple if you ad the width and heigh of one rect to another(with the appropriate half offsets), then it just becomes a point in rect test.

Re: Pythagoras theorem for colission detection between squares

Posted: Tue Jun 15, 2010 2:03 pm
by Zer0XoL
Ginto8 wrote:
Zer0XoL wrote:So you are saying i should use normal collision detection for squares? Yeah I probably should, but i want to see if its possible with this, and if so then i could probably use it with rotating squares too.
Im just interested in if something like this is possible, not for what i should use but tnx anyway :P
It depends. Circular collision detection is a LOT less expensive than SAT for when things are far away. Using circular for an initial collision detection is perfect, because if you have a circle circumscribed around the rects and those circles aren't touching, there's NO way the rects can be touching. So for OBBs using circular collision for an initial check is very good. For AABBs, circular detection is just a waste of CPU.
yeah, tnx :)

Re: Pythagoras theorem for colission detection between squares

Posted: Tue Jun 15, 2010 2:05 pm
by Zer0XoL
avansc wrote:If you want to to simple AABB rect collision you can make it about half as simple if you ad the width and heigh of one rect to another(with the appropriate half offsets), then it just becomes a point in rect test.
that seems nice :) i should probably check this AABB out, thx :D