Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I program a simulation of physics?

I am trying to create a Java package that can be used to write simulation programs. My goal is to create 'objects' like springs or solid objects like cubes and spheres. They will have mass, velocity, gravity etc. and they can interact with each other.

I have seen some simulation programs on www.myphysicslab.com but my problem is that I don't want to write different equations for different senarios. Is there any way to do this? I am new to programming.

like image 298
Mahendra Chouhan Avatar asked Jul 16 '11 20:07

Mahendra Chouhan


3 Answers

Creating a physics engine is hard. (Very hard). But it can also be a lot of fun. Well, fun in a "why am I doing this to myself?" kind of way.

Assuming your have a fair grasp of the maths involved*, and assuming you're interested in Rigid Body Dynamics there are a couple of classic references to start with:

  • First of all Chris Hecker's Rigid Body Dynamics tutorials
  • And of course Witkin and Baraff's SIGGRAPH course

Those are good places to start and will provide more than enough of a challenge for you.

You could also look at Box2D by Erin Catto and his associated GDC tutorials which you can download.

For more specific help, the forums for Bullet also contain a sub-section where you can discuss and ask questions once you have understood some of the basics.

*If you don't have this fair grasp, learn. If you're not willing to, don't try and just use an existing engine. If this is your very first programming experience, just focus on the programming first. Don't get yourself overwhelmed.

Good luck.

like image 120
Bart Avatar answered Sep 27 '22 23:09

Bart


To understand physics, you must first understand maths. Attempting to write a physics engine without using mathematical equations is like making a cake without ingredients.

Entire careers are built on creating physics engines, so my advice is to either use an existing engine, or get your books out.

like image 31
adlawson Avatar answered Sep 27 '22 23:09

adlawson


Building a physics simulator can be a lot of work. Two dimensions is considerably simpler than three, so maybe you want to start with 2D. You might want to begin with an existing package like JBox2D. It has a constraint solver, friction, etc. You can build on top of JBox2D or study how it works.

An HTML5 version is available with online demos: GWTBox2D

like image 22
Kipton Barros Avatar answered Sep 27 '22 22:09

Kipton Barros