General collision detection technique question (maybe simple)

• 10-10-2007
thisismatt
General collision detection technique question (maybe simple)
Hopefully this isn't extremely complicated...maybe it doesn't require advanced collision detection techniques at all, I don't really know, so I'm looking for a general idea how I might go about it.

I want to test for collision between an object (flying arrow) moving in a parabolic arc and another stationary or moving 3D object. I suppose the tip of the arrow could be considered as a small sphere, and nothing really needs to occur upon collision other than knowing the collision itself occurred.

I'm not looking for someone to write me any code, I'm simply interested in ideas or pointers. Thanks
• 10-10-2007
dwks
Well, if the objects you are detecting a collision between are both spherical, then it's quite simple to detect if they are in contact. Just take the distance between the objects with the formula
Code:

`distance = sqrt(x*x + y*y)`
which is a simple derivative of Pythagora's theorem:
Code:

`c^2 = a^2 + b^2`
There's actually a C99 function called hypot() which does just this, in a better way -- because if you just used the literal equation, x*x or y*y might overflow. But it's C99 only as far as I am aware.

You can derive simple formulae for other collisions as well. For example, if the arrow was a sphere and the ground was flat, you would just take the vertical component of their separation and use that.

Collision detection can get a lot more complicated that this, of course. You might want to post some more information -- for example, what is the circular arrow colliding with?
• 10-10-2007
IdioticCreation
I think it would be easier, and more resourceful if the tip of the arrow was represented as a single point, rather then a circle. Then you could use bounding boxes, or the distance formula that dwks explained.
• 10-10-2007
thisismatt
Sorry, I guess I should have stated I'd be doing it in OpenGL, too. Sure, I think the tip of the arrow could be represented as a point. I'd like to be able to test for collision against various shapes, not just spheres or other primitives, but nothing super detailed (eg a basic duck shape, balloon, bullseye made up of cylinders or discs).

Thanks for the help!
• 10-10-2007
VirtualAce
Quote:

I'd like to be able to test for collision against various shapes, not just spheres or other primitives, but nothing super detailed (eg a basic duck shape, balloon, bullseye made up of cylinders or discs).
Your objects need bounding volumes to approximate their shape. This is the trivial rejection test. Once that passes then you can move on to more expensive testing.

As long as you work in terms of the square of the distance, spheres will work just fine.