Write a function ball_collide that takes two balls as parameters and computes if they are colliding. Your function should return a Boolean representing whether or not the balls are colliding. Hint: Represent a ball on a plane as a tuple of (x, y, r), r being the radius, if (distance between two balls centers) <= (sum of their radii) then (they are colliding)
def ball_collide(x1,y1,r1,x2,y2,r2):
dist=((x2-x1)**2+(y2-y1)**2)**0.5
center=dist/2
print("Collision Point",center)
r=r1+r2
print("Sum of radius",r)
if(center<=r):
print("Balls are Colliding")
return True
else:
print("Balls are not Colliding")
return False
c=ball_collide(4,4,3,2,2,3)
print(c)
c=ball_collide(100,200,20,200,100,10)
print(c)
Comments
Post a Comment