Here I made a bouncing ball using mixed integer programming in cvxpy. Currently we are just simulating the bouncing ball internal to a mixed integer program. We could turn this into a control program by making the constraint that you have to shoot a ball through a hoop and have it figure out the appropriate initial shooting velocity.

The trick I used this time is to make boolean indicator variables for whether a collision will happen or not. The big M trick is then used to actually make the variable reflect whether the predicted position will be outside the wall at x=0. If it isn’t, it uses regular gravity dynamics. If it will, it uses velocity reversing bounce dynamics

Just gonna dump this draft out there since I’ve moved on (I’ll edit this if I come back to it). You can embed collisions in mixed integer programming. I did it below using a strong acceleration force that turns on when you enter the floor. What this corresponds to is a piecewise linear potential barrier.

Such a formulation might be interesting for the trajectory optimization of shooting a hoop, playing Pachinko, Beer Pong, or Pinball.

MATLAB

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

using JuMP

using Cbc

using Plots

N=50

T=5

dt=T/N

m=Model(solver=CbcSolver())

@variable(m,x[1:N])#,Bin

@variable(m,v[1:N])#,Bin

@variable(m,f[1:N-1])

@variable(m,a[1:N-1],Bin)#,Bin

@constraint(m,x[1]==1)

@constraint(m,v[1]==0)

M=10

fortin1:N-1

@constraint(m,x[t+1]==x[t]+dt*v[t])

@constraint(m,v[t+1]==v[t]+dt*(10*(1-a[t])-1))

#@constraint(m,v[t+1]==v[t]+dt*(10*f[t]-1))

@constraint(m,M*a[t]>=x[t+1])#ifon the next step projects into the earth

@constraint(m,M*(1-a[t])>=-x[t+1])

#@constraint(m,f[t]<=M*(1-a[t]))#we allowabouncing force

end

k=10

#@constraint(m,f.>=0)

#@constraint(m,f.>=-k*x[2:N])

#@constraint(m,x[:].>=0)

E=1#sum(f)#1#sum(x)#sum(f)#+10*sum(x)#sum(a)

@objective(m,Min,E)

solve(m)

println(x)

println(getvalue(x))

plotly()

plot(getvalue(x))

#plot(getvalue(a))

gui()

More things to consider:

Is this method trash? Yes. You can actually embed the mirror law of collisions directly without needing to using a funky barrier potential.

You can extend this to ball trapped in polygon, or a ball that is restricted from entering obstacle polygons. Check out the IRIS project – break up region into convex regions