

I finally ported my C++ demo code to a JavaScript demo that runs in a web browser using ChatGPT. The first version of this code was written in 2003 for a SIGGRAPH course on simulating and controlling nature. I then subsequently showed it during many invited and keynote talks to illustrate how optimization/machine learning works in the context of physical simulation. More precisely, constrained optimization. There are four ingredients. 1) a state, 2) a control, 3) a cost function and 4) a constraint.
​
I illustrate constrained optimized with a simple example of a cannon trying to hit a target. In this case. The control is the angle at which the cannon shoots the ball. The target is a user specified point that you can move with right mouse button. The cost function is the distance squared between the target's position and where the cannon ball lands. And finally the ball is constrained to lie on the parabolic solution given by the initial position and velocity of the cannon ball. The goal is to hit the target. You can achieve this by changing the angle of the cannon manually. Notice that there are two solutions. Now by using the gradient we can find a minimum automatically by following the negative gradient. You can see this in action by enabling "gradient descent". Depending on the current angle you end up in one of the minima. By enabling the "smoothing term" you can add a cost term that minimizes travel time. This results in a global minimum.
​
Some thoughts on using AI. At first I tried to have the AI create the web app from a detailed description of what I wanted to achieve. At first I thought a small build up of the app by starting with the cannon ball simulation and then progressively adding features would do the trick like I usually code. The AI was constantly rebuilding the app from scratch with bugs and a new look at each time! After half a day I gave up. Then I just told the AI to take my old cpp code with OpenGL, GLUT and GUI and create a web Javascript app. After a few minutes it pretty much spitted out the app above. Which I then tweaked a little manually since I know the rudiments of Javascript. So will AI replace programmers? Maybe with a better intermediate language. A generic high level language that can then be translated in a local patois like C++ or Javascript or whatnot. Just like compilers removed the need for writing everything in assembly language.
​
This demo was shown in this SIGGRAPH 2019 special Nvidia event.
​​​
