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
Pythagoras theorem for colission detection between squares
Moderator: Coders of Rage
- Bullet Pulse
- Chaos Rift Cool Newbie
- Posts: 89
- Joined: Sun Feb 21, 2010 6:25 pm
Re: Pythagoras theorem for colission detection between squares
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.
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.
- Bakkon
- Chaos Rift Junior
- Posts: 384
- Joined: Wed May 20, 2009 2:38 pm
- Programming Language of Choice: C++
- Location: Indiana
Re: Pythagoras theorem for colission detection between squares
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.
- Zer0XoL
- ES Beta Backer
- Posts: 54
- Joined: Fri Apr 24, 2009 1:18 pm
- Current Project: Zelda untitled multiplayer game
- Favorite Gaming Platforms: PC, GBA, N64
- Programming Language of Choice: C++, Lua
- Location: Sweden
- Contact:
Re: Pythagoras theorem for colission detection between squares
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
Im just interested in if something like this is possible, not for what i should use but tnx anyway :P
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Pythagoras theorem for colission detection between squares
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.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
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Re: Pythagoras theorem for colission detection between squares
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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- Zer0XoL
- ES Beta Backer
- Posts: 54
- Joined: Fri Apr 24, 2009 1:18 pm
- Current Project: Zelda untitled multiplayer game
- Favorite Gaming Platforms: PC, GBA, N64
- Programming Language of Choice: C++, Lua
- Location: Sweden
- Contact:
Re: Pythagoras theorem for colission detection between squares
yeah, tnxGinto8 wrote: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.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
- Zer0XoL
- ES Beta Backer
- Posts: 54
- Joined: Fri Apr 24, 2009 1:18 pm
- Current Project: Zelda untitled multiplayer game
- Favorite Gaming Platforms: PC, GBA, N64
- Programming Language of Choice: C++, Lua
- Location: Sweden
- Contact:
Re: Pythagoras theorem for colission detection between squares
that seems nice i should probably check this AABB out, thx :Davansc 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.