Simulating Car Dynamics with a Computer Program: Part III
We will have another data structure (with the same format) for car-240, another for car-70, and so on. We get to choose these names to be almost anything we like (It so happens, annoyingly, that we can't use the word car. This is a Scheme reserved word, like define. Its use is explained later). So, we would create all the data structures for the cars in our simulation with expressions like the following:
The state of a race car consists of several numbers describing the physics of the car. First, there is the car's position. Imagine a map of the course. Every position on the map is denoted by a pair of coordinates, x and y. For elevation changes, we add a height coordinate, z. The position of the centre of gravity of a car at any time is denoted with expressions such as the following:
Each of these expressions performs data retrieval on the data structure car-161. The value of the first expression is the x coordinate of the car, etc. Normally, when running the Scheme interpreter, typing an expression simply causes its value to be printed, so we would see the car position coordinates printed out as we typed. We could also store these positions in another block of computer memory for further manipulations, or we could specify various mathematical operations to be performed on them.