Watch the ball intercept the cat. This program works as long as the object can be intercepted. Change the position, speed and direction values inside the project to test it out in different ways if you want. Here are the definitions of the abbreviated variables: t = time of interception d = direction of object being intercepted S1 = speed of object being intercepted S2 = speed of intercepting object (x1, y1) = position of the object being intercepted (x2, y2) = position of intercepting object POI = position where the intercepting object intercepts the intercepted object
This program is not 100 percent accurate regarding the minimum time it takes the intercepter to intercept the object because I adjusted my equations so that they would be easier to implement on scratch. Here are the original equations I made if anyone wants to improve my algorithm: 1. (((x1-x2)+(cos(d)*t*S1))²+((y1-y2)+(sin(d)*t*S1))²)½ = S2*t (Use equation #1 to solve for t) 2. POI = (x1+cos(d)*S1*t, y1+sin(d)*S1*t) Let me know what you think of my algorithm