hspn reviews
 

Categories
Search


Advanced Search
Advertisement

Article Options
Popular Articles
  1. Will Installing It Void My Warranty
  2. Engine Management Is The Smartest Bang for The Buck on The STi
  3. Selecting a Catback Exhaust for my STI
  4. Searching for a Lightweight One-Piece Driveshaft.
  5. How do I become a rally driver?
No popular articles found.
Popular Authors
  1. Kevin Lawrence
  2. Michael Anthony
  3. Nick Luhr
  4. Brian Beckman
  5. Alex Racanelli
  6. Josh Fowler
  7. Drift.com
  8. Aaron Ekinaka
  9. Ben Fried
No popular authors found.

 »  Home  »  Editorials / Articles  »  Physics of Racing  »  The Physics of Racing, Part 8: Simulating Car Dynamics with a Computer Program
The Physics of Racing, Part 8: Simulating Car Dynamics with a Computer Program
By Brian Beckman | Published  05/29/2006 | Physics of Racing | Unrated
Simulating Car Dynamics with a Computer Program: Part II

The first thing we need to do is create a data structure that contains the mathematical state of the car at any time. This data structure is a block of computer memory. As simulated time progresses, mathematical operations performed on the data structure simulate the physics. We create a new instance of this data structure by typing the following on the computer keyboard at the Scheme prompt:

(new-race-car)

This is an example of an expression. The expression includes the parentheses. When it is typed in, it is evaluated immediately. When we say that Scheme is an interactive programming language, we mean that it evaluates expressions immediately. Later on, I show how we define this expression. It is by defining such expressions that we write our simulation program.

Everything in Scheme is an expression (that's why Scheme is simple). Every expression has a value. The value of the expression above is the new data structure itself. We need to give the new data structure a name so we can refer to it in later expressions:

(define car-161 (new-race-car))

This expression illustrates two Scheme features. The first is that expressions can contain sub-expressions inside them. The inside expressions are called nested. Scheme figures out which expressions are nested by counting parentheses. It is partly by nesting expressions that we build up the complexity needed to simulate racing. The second feature is the use of the special Scheme word define. This causes the immediately following word to become a stand-in synonym for the value just after. The technical name for such a stand-in synonym is variable. Thus, the expression car-161, wherever it appears after the define expression, is a synonym for the data structure created by the nested expression (new-race-car).

Comments