part of 3d tech for the web course
coordinates and triangles
some trigonometry
pythagorus
code
Goal: To Tell if two Object Have Collided
Collided Means: When their centres are closer than the sum of their sizes
Centres: position coordinates
Sizes: a number representing radius (say)
// PSEUDOCODE
if ( distance_between(object_a, object_b) < size(object_a) + size(object_b))
{
output ("COLLISION");
// DO SOMETHING
}
distance = Math.sqrt(
((firstBall.x - secondBall.x) * (firstBall.x – secondBall.x))
+ ((firstBall.y - secondBall.y) * (firstBall.y – secondBall.y))
);
if (distance < firstBall.radius + secondBall.radius)
{
//balls have collided
}