Tuesday April 16, 2024
 The Maths of 3D You can't have 3D without a little maths...

Collision Detection

by bkenwright@xbdev.net

Putting together various demo programs that show how you would go about testing for intersection tests with various common shapes, and how to determine the intersection point.  You usually determine if a collision has occured, then using the intersection point, determine how to react to the collision, as in games if a ball hit a wall you would want to know the hit point to you would work out where the ball would bounce back from :)

 Triangle Ray Collision Intersection Demo

 Sphere Ray Collision Intersection Demo

 Sphere - Sphere Collision Detection Demo

 AABB - AABB Collision Detection Demo

 Ray-Plane Intersection Demo

 BaryCentric Coordinates

 BaryCentric Coordinates is a way of representing a set of weighted values for each point.  The concept is used in numerous tests not just our triangle/point demo.  P = uA + vB + wC   P is our point, A,B,C our triangle and of course u,v,w are our Barycentric coordinates.   where u+v+w=1   The point is inside the triangle only if 0<= u,v,w <= 1,  or alternatively, if and only if 0<=v<=1.0f and 0<=w<=1 and  v+w<=1   Not that I say v+w<=1, as u=1-w-v   Which leads us to rearranging for what u is, and gives us:   P = A + v(B-A) + w(C-A) = (1-v-w)A + vB + wC   And we can solve for v and w.

Quick View of the Various Intersection / Collision Detection Algorithms Source

Useful DirectX Librarys

• D3DXPlaneIntersectLine(..) - return the point on the plane or NULL if parallel