Newtonian physics gives a way to predict the future state of a system of massive objects in a Euclidean space. This gem provides a library of classes such as Point, Vector, Force. This gem enables a system built from these classes to be evolved forward in time according to Newton's laws of motion.
Note: all bold quantities are vectors. SI units are assumed everywhere, here's a brief list in case you don't remember all the SI units:
- Time is measured in seconds (s)
- Length is measured in meters (m)
- Mass is measured in kilograms (kg)
There are more, but none are relevant to the newtonian library, it only deals with space, time and mass.
The unit for force is sometimes abbreviated (N), as Newtons, but it is defined in terms of kilograms, meters and seconds.
Newton's laws of motion
An object either remains at rest or continues to move at a constant velocity unless acted upon by a force.
The vector sum of external forces F acting on an object is equal to the object's mass m times the acceleration vector a.
When one body exerts a force on another body, the other body exerts an equal and opposite force on the original body.
The second law can be summarized as:
F = m a
The third law can be summarized as:
F1 = -F2
Conservation of momentum
Newton derived the conservation of momentum from his three laws, but later developments in physics, such as electromagnetism and quantum mechanics show that conservation of momentum is actually the more fundamental principle, so I will state it here axiomatically.
Momentum is usually denoted with a p, and it is defines as the product of an objects mass and velocity:
p = mv
Newton's second and third laws can also be summarized as
F = (d/dt)p
Where (d/dt) means the "rate of change with respect to time". If you are not familiar with calculus, this is called a derivative.
Newton's law of universal gravitation
Given two objects with masses m1 and m2, the force of gravity on object two from object one is:
F21 = (Gm1m2/r2)r̂21
Where r = ||r21|| (the norm (length) of the vector from object 2 to object 1), and
r̂21 is a vector in the direction of r21, but with a magnitude (norm) of 1.
And G is the gravitational constant: 6.673×10−11 N (m/kg)2
Run example simulation
And then open your browser to http://localhost:8000
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install newtonian
TODO: Write usage instructions here
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/tlehman/newtonian.
The gem is available as open source under the terms of the MIT License.