Object-Oriented Programming
Object Oriented Orbits: A Primer on Newtonian Physics

Summarized using AI

Object Oriented Orbits: A Primer on Newtonian Physics

Tobi Lehman • March 31, 2016 • Earth

In the talk "Object Oriented Orbits: A Primer on Newtonian Physics" by Tobi Lehman, the speaker provides a comprehensive introduction to simulating orbits within the framework of Newtonian physics, utilizing the Ruby programming language to create a basic 2D physics simulator. The key points of the presentation include:

  • Complete Model of Space: The discussion begins with an exploration of Euclid's five axioms that form the foundation for modeling space, crucial for simulating orbits.

  • Vectors and Geometry: The speaker explains the significance of vectors, emphasizing their geometric properties, operations (addition, scalar multiplication), and how they can be computed in a programming context.

  • Dynamic Rules: The motion of celestial bodies is governed by dynamic rules involving velocity and acceleration. The presenter delves into the application of Newton's laws, notably how they facilitate the advancement of a system's state over time.

  • Newton's Laws: Newton’s first and second laws are detailed, presenting how the total forces acting on a body can be calculated using the law of universal gravitation while focusing on forces between multiple bodies in a simulated environment.

  • Implementation in Ruby: The crux of the presentation involves converting theoretical concepts into practical Ruby code. Variably updated states of bodies are rendered using HTML5 canvas in a web-based environment, which engages the audience through live coding and real-time results.

  • Simulation Demonstrations: Several demonstrations illustrate core principles, including binary star systems and chaotic three-body simulations, highlighting the stability of two-body systems against the unpredictable nature of three-body interactions.

  • Conclusions and Observations: The talk concludes with the acknowledgment of the beautiful complexity of gravity and multi-body dynamics and nods to the potential future explorations in the realms of relativity and quantum mechanics.

Overall, Lehman’s presentation effectively combines theoretical physics, programming, and visual simulation to depict orbital mechanics, emphasizing the engaging nature of computational physics education.

Object Oriented Orbits: A Primer on Newtonian Physics
Tobi Lehman • March 31, 2016 • Earth

In this talk, we derive a simple 2D physics simulator, focusing on gravity and spherical objects. The speaker walks through a basic introduction to Newton's laws, and then derives a formula for a discrete approximation of the equations of motion. We convert the discrete approximation of the equations of motion into Ruby code, which accepts a state at a particular time, along with an interval of time, and then computes the new state at that following time interval. This updated state is then rendered using an HTML5 canvas element. The talk concludes with some demonstrations involving randomized initial conditions, highly symmetric initial conditions, and some awesome 3-body stable orbits.

Ruby on Ales 2016

00:00:13.250 All right, how's the sound? Give me an okay. All right, okay. So, what does it take to simulate orbits? Before we can actually do that, we're going to need a couple of things.
00:00:20.939 The first thing that we're going to need is a complete model of space. After that, we're going to need a dynamic rule to update the state of the bodies in our space.
00:00:25.949 These two things together should be sufficient for simulating an orbit, or at least getting something that kind of looks orbit-like. The first complete model of space was compiled by Euclid over 2,000 years ago, and it's still good today; it's good enough to get the Apollo missions to the moon.
00:00:38.040 We're going to study that model, which consists of five axioms and a collection of definitions. However, I'm just going to cover the axioms here. The first axiom states that between any two points A and B, a line segment L can be drawn.
00:00:55.440 Axiom two states that given any line segment, you can extend that line segment indefinitely in one direction, creating a larger line segment that contains the original one. The third axiom says that a circle can be drawn at any point with any radius.
00:01:06.720 The fourth axiom states that all right angles are congruent, meaning that given any two right angles, you can line them up in a consistent manner. Lastly, we have the parallel postulate, which states that given any line and a point not on that line, there is exactly one other line that runs through that point and does not intersect the original line. This is our definition of parallel, which is very special and will be useful later.
00:01:41.100 Using these almost trivial five axioms, we can derive some useful concepts. One concept you probably recognize from high school is the Pythagorean theorem. Its relevance to simulating planets and orbits is mainly in calculating distances.
00:02:06.930 Imagine we have a body like the Sun and another body like the Earth. We can use a coordinate system to find the numbers A and B, then use this formula to calculate the distance between them. This gives us another useful tool for figuring out the force between them.
00:02:33.100 We're going to use vectors. Vectors are just directed line segments, and they can also be scaled by a real number. For example, if we have some vector V, we can scale it by multiplying it by a real number.
00:03:06.790 In terms of terminology, we'll call the arrowhead part the head of the vector, while the other end is the tail. You can think of vectors as representing a displacement from the tail to the head.
00:03:17.650 Vectors are really useful because they can be added together. The operation of addition can be defined geometrically. Given any two vectors with the same tail, we can add them together.
00:03:29.470 To add the two vectors, we take one vector and go from the tail to its head, then travel along another vector that is parallel to the other vector. Geometrically, this shows that addition of vectors is a commutative operation, meaning V plus W equals W plus V.
00:03:54.370 Vectors don't just have geometric significance. What we really want is to do calculations with them and ultimately process them in a computer, which handles numbers and arrays. To transition from a geometric representation to something we can compute with, we must choose a coordinate system. We can select any three mutually perpendicular axes as our coordinate system.
00:04:33.190 Once we choose that set of axes and a unit of measurement, we can count along each axis and write down the numbers for the direction in which the vector travels. In this way, we can express vectors in terms of a triple of numbers in three-dimensional space.
00:05:17.680 This establishes a connection between geometry, vector representation, and the code we'll implement later. Additionally, vectors can be represented in an array format, and we can define the dot product operation. This involves multiplying corresponding components of two vectors and summing them up.
00:05:34.810 The dot product gives us information about the length of the vectors and the angle between them. For instance, if we take a vector and dot it with itself, the result is equivalent to the sum of the squares of its components, which relates to the length.
00:06:06.729 To find the length of a vector, we can dot it with itself and then take the square root. This helps us represent the positions of the bodies we're trying to simulate. To find the distance between two bodies, we subtract the vectors representing their positions.
00:06:58.789 Using the definitions we've established, we can multiply one vector by a scalar of -1 and then add them together. This provides a new vector representing the distance from one point to another. When we dot this resultant vector with itself, we obtain the distance between those two points.
00:07:17.680 Now that we have our first abstraction, we can define some code. We'll have a wrapper class called Vector, which will contain an array of components. Initialization of the vector will be straightforward.
00:07:30.529 Next, we will implement the algebraic operations on vectors. We want to include addition and scalar multiplication. For adding vectors, we can utilize the parallelogram law we saw earlier. Once the vector is in component form, we simply add the corresponding components together using the zip method.
00:08:08.209 The zip method combines two arrays of equal length and produces a new array where each element consists of paired values. Sum those pairs together, and you'll arrive at a single new vector that represents their sum. Scalar multiplication is also easy; just multiply each component of the vector by the scalar.
00:08:29.059 In addition, we want to check whether two vectors are equal. Most importantly, we want to be able to compute the dot product. We again use the zip method for this and multiply the components together before summing them up to get the dot product.
00:09:06.290 So now we have a model of space, but we need to move on to the dynamic rule, which is where things get a bit more complicated but also more interesting. We can represent bodies in space and compute distances, as well as represent the state of a system at a moment in time.
00:09:20.780 However, we also want to be able to advance that state over time to see how things play out. To do this, we need to discuss velocity and acceleration. We want to simulate a path for a body, which can be illustrated as a sequence of vectors.
00:09:52.460 At any moment in time, we can organize these vectors with a function X of T, where the arrow above the X denotes a vector and represents the position at time T. Given a function that specifies the position of a body at a particular time, we can easily calculate its velocity.
00:10:13.490 In basic terms, velocity is described as the displacement in position divided by the displacement in time. If we consider a small amount of time into the future, we can measure the displacement in that time interval and scale it by the reciprocal of the time; this gives us the velocity vector.
00:10:39.170 There is a similar relationship between acceleration and velocity. Acceleration is the rate of change of velocity, while velocity is the rate of change of position.
00:11:07.420 If there is no acceleration, applying Newton’s first law allows us to determine the position vector, which states that if there are no forces acting on a body, it travels in a straight line. If we have an initial position and velocity, the body will simply trace a straight line along that velocity vector.
00:11:41.350 Now, Newton's second law, represented as F = ma, can be decomposed into its components. Although it’s easy to remember F = ma, in practice, it’s crucial to consider the various individual forces acting on an object.
00:12:10.389 We need to be able to calculate the total force on a body. Imagine you have several bodies you want to simulate, and for each one, you want the total force acting on it. If we denote the number of bodies as n, you want to calculate the force on body i by accounting for every other body.
00:12:29.629 The way to calculate each of these forces is by using Newton's law of universal gravitation. This law is famously illustrated through an anecdote involving an apple, but it’s a crucial concept we can use in our simulation. Although we can ignore the gravitational constant for simplicity, it’s roughly sufficient to set it to one in our models.
00:13:12.490 The value of R in our equations represents the distance between the bodies. When calculating the force due to gravitation, it is essential to consider that this R represents a vector normalized to unity, meaning it has a length of one.
00:13:40.689 The force between two bodies is inversely proportional to the square of the distance between them. In three dimensions, if you visualize a sphere with radius R around a mass, the amount of gravitational influence spreads over the surface area of the sphere. As the radius increases, the same amount of energy is spread over a larger area, resulting in a decrease in gravitational strength.
00:14:57.270 This phenomena reflects the geometric nature of gravity in three-dimensional space, a concept derived from many observations by Newton and fundamental geometrical understanding.
00:15:34.730 Next, we want to represent bodies in our simulation. A body has relevant data such as mass, position, and velocity. In our code, we will plug in the initial conditions and continually update these states as time progresses.
00:16:04.030 It’s important to note that Newton's laws do not concern themselves with the radius or shapes of bodies. Only total mass and center of mass matter. For example, if we imagine collapsing the Sun into a black hole without changing its mass or center of mass, the orbits of the planets would remain unchanged.
00:16:38.300 In our simulation, we will treat bodies as if their mass is concentrated at a single point. Next, we will implement Newton's law of universal gravitation by calculating the force exerted by one body on another.
00:17:19.060 Using the formula, we can calculate the norm, which represents the distance from one body to another and apply it in our primary formula to compute the gravitational force.
00:17:49.750 Moving on, we have to tackle the concept of the universe in our simulation. The universe is vast and difficult to comprehend. We will represent it in Ruby, configuring it to maintain a certain number of dimensions and bodies.
00:18:14.630 We must identify that time within the computer correlates with time in our simulation, so one second in computer time represents one second in simulated time. This means we will update the states of all bodies in real-time.
00:18:48.280 Each body won't inherently know about other bodies in the universe; rather, the universe will provide each body with information regarding the other bodies for calculations.
00:19:20.980 This leads to a critical section where we calculate the forces between each unique pair of bodies in the universe, summing forces for body i from each body j.
00:20:03.660 We need to sum the forces acting on body i, effectively yielding the left side of our F = ma equation. From here, we'll update the body positions and accelerations.
00:20:24.540 Acceleration is calculated by dividing the total force by the mass of the body. Once we obtain the acceleration, we can also compute the change in velocity.
00:20:54.020 Velocity is derived from acceleration as the rate of change of acceleration. We multiply the acceleration by the time interval (in seconds) to derive the change in velocity.
00:21:16.350 Position change is similarly computed, as the velocity multiplied by the time interval will yield the positional displacement over that time.
00:21:57.020 In the simulation, I've used a millisecond time step, but it must be sufficiently small for our calculations to remain accurate.
00:22:40.230 Our calculations and implementations will take place within Ruby. Although I'm not entirely familiar with graphical libraries for Ruby, I thought it would be interesting to stream the result to a browser using an HTML5 canvas.
00:23:11.180 To accomplish this, I wrote a web server and also utilized a WebSocket server to manage communication. I found a great tool called WebSocket d, which maps standard input and output into the WebSocket connection.
00:23:43.900 Running both a web server and a WebSocket server can get tricky. We need to run the web server in the background, allowing it to communicate with the WebSocket server seamlessly.
00:24:24.510 Now, let’s discuss the simulation examples. The first application we're going to showcase is a binary star system. In this simulation, we have two bodies with equal mass moving circularly around a common center of mass.
00:25:13.350 Uniform circular motion refers to this predictable movement, where centripetal acceleration acts inward, maintaining the circular path, hence avoiding flying off into space.
00:25:58.340 We can determine the appropriate initial velocities required to maintain stable orbits as they revolve around a center of mass.
00:26:21.410 Let's see if the WebSocket server and simulation integration works properly. After running a few tests, we observe that it’s operational! I'll now demonstrate the live simulation.
00:27:09.890 As we run the simulation, you’ll see two bodies in synchronous motion, elegantly rotating around their common center of mass.
00:27:32.080 Through collaborative live coding, we can resolve any arising issues as they occur, which adds an interactive layer to the presentation.
00:28:10.760 During the simulation, we can examine and adjust parameters, observing the effects of changes in velocity and position.
00:28:45.310 With requestAnimationFrame in the browser, the WebSocket server streams a series of updates to ensure the current state is accurately reflected for rendering.
00:29:47.000 This responsiveness means that when you navigate away from the webpage, the rendering temporarily halts, enhancing efficiency.
00:30:11.140 The simulation is fully integrated into a GitHub repository, allowing for public accessibility and interaction during and after the presentation.
00:30:42.130 We only deal with two-body systems to keep it straightforward, which can often be solved analytically without numerical simulations, providing paths over time.
00:31:21.109 However, once we introduce a third body, it becomes generally impossible to solve analytically due to the chaotic nature of multi-body gravitational interactions.
00:31:55.829 To demonstrate this complexity, I’ll present an example involving three bodies in a stable orbit traced in the shape of a lemniscate. The initial conditions are carefully set to create this symmetrical figure-eight pattern.
00:32:51.520 Running this simulation gives us insight into the intricate dynamics at play. Observing this motion can be mesmerizing and reveals the delicate balance needed to maintain the stable orbit.
00:33:41.530 This behavior, however, illustrates how other complex simulations may lead to instability or chaotic behavior over time, even if they appear stable initially.
00:34:24.800 Thus, random initial conditions are another fascinating aspect of these simulations. They display how initial placements can lead to vastly different trajectories in a multi-body system.
00:34:50.440 While Newtonian mechanics provides a solid foundation for understanding motion and forces, the future of physics beckons with theories of relativity and quantum mechanics populating newer branches.
00:35:11.628 Thank you so much for providing such wonderful debugging support during the presentation. Your attention and questions make this endeavor even more enjoyable.
Explore all talks recorded at Ruby on Ales 2016
+5