User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

3D Collision Detection

Fri Aug 28, 2015 7:14 pm

Has anyone got a collision detection function for 3D spheres?
I'm not being googlazy (just invented that word), all I can find are references to Panda3D, PyODE, VRPlumber, etc. and I don't need a full package, just a function to which I can pass xyz co-ordinates, velocities and radii and get the relevant info back.

Any help appreciated.
Dave.
Apple say... Monkey do !!

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

Re: 3D Collision Detection

Fri Aug 28, 2015 7:33 pm

If they are spheres it's easy maths !

sphere 1 center at (x1,y1,z1) sphere 2 center at (x2,y2,z2)
sphere 1 radius r1 sphere 2 radius r2

d = sqrt( ((x1-x2)^2) + ((y1-y2)^2) + ((z1-z2)^2))

if (d < (r1+r2) ) then collided

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: 3D Collision Detection

Fri Aug 28, 2015 7:43 pm

Thanks Peter but I need the bounce as well, probably should have mentioned that..

Dave.
Apple say... Monkey do !!

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

Re: 3D Collision Detection

Fri Aug 28, 2015 8:05 pm

You probably DO need the "full package" then ! I've used ODE (from C) in the past so I would expect PyODE to be fairly straight forward.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Python”