Thread: General collision detection technique question (maybe simple)

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    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

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    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.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    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!

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General Guidelines on Preventing Header File collision
    By stanlvw in forum C++ Programming
    Replies: 12
    Last Post: 07-05-2008, 04:02 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. simple collision detection question
    By godhand in forum Game Programming
    Replies: 2
    Last Post: 05-25-2004, 11:27 PM
  4. Replies: 4
    Last Post: 05-03-2002, 09:40 PM
  5. General Question
    By GSLR in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-02-2002, 12:15 PM