# -*- coding: utf-8 -*-
# ball_collide.py
# MIT OCW 6.189 Homework 3
# Exercise 3.2 – Collision Detection of Balls
# Mechanical MOOC
# Judy Young
# July 23, 2013
# To ﬁgure out if two balls are colliding, we need to compute the distance 
# between their centers, then see if this distance is less than or equal to 
# the sum of their radii. If so, they are colliding.

import math

def ball_collide(ball_1, ball_2):
    
    sumRadii = float(ball_1[3] + ball_2[3])
    xDiffSquared = (float(ball_1[0]) - float(ball_2[0]))**2
    yDiffSquared = (float(ball_1[1]) - float(ball_2[1]))**2
    zDiffSquared = (float(ball_1[2]) - float(ball_2[2]))**2
    centreDistance = math.sqrt( xDiffSquared + yDiffSquared + zDiffSquared )

    print "\nball_1", ball_1
    print "ball_2", ball_2
    print "sumRadii = ", sumRadii
    print "xDiffSquared = ", xDiffSquared
    print "yDiffSquared = ", yDiffSquared
    print "zDiffSquared = ", zDiffSquared
    print "centreDistance = ", centreDistance

    if centreDistance > sumRadii:
        return "All Clear\n"
    else:
        return "CRASH!\n"
    
print "Balls small, far apart", ball_collide((0,0,0,1), (7,7,7,1))
print "Both balls the same size, in the same place", ball_collide((0,0,0,1), (0,0,0,1))
print "Both balls in the same place, different sizes", ball_collide((0,0,0,1), (0,0,0,7))
print "Balls just touching", ball_collide((0,0,0,1), (0,2,0,1))
print "Balls small, far apart, each side of 0,0,0", ball_collide((-5,-5,-5,1), (0,2,0,1))