Car dynamics experiment

This application simulates movements of a car.
There's a special physics system in this application. It's based on particles but you can use several particles to form a rigid body.
Every particle has its mass, and when they were formed into a rigid body, the system calculates the center of gravity and moment of inertia for the rigid body. When a force was applyed to a particle, the physics system calculates acceleration and rotational acceleration for the whole rigid body and make it move.
To simulate the car, I used 4 particles (one for each wheel) to form the car rigid body. Thrusts and frictions were applyed to these wheels.
The friction calculation is special. Since wheels have direction. In the same direction of their rotation, they are free to move. But on the perpendicular direction of their rotation, they tends to stop the movement (Actually it's this friction that makes the car turns).

So here is the result:

First choose peremeters for your car, then click "drive" to drive it.
Use arrow keys to control the car.

You can change the shape of the car by these parameters, and you will see it acts differently for different settings. That's the magic of physics.

But this physics system is not quite complete, there's no collision detection and constraints... Since there's many wonderful physics engine under development now, I think I'm not going to complete this one.

There is also a 3D version here.
Source code download

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.