You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
14.4 That also implies that $\sqrt{\vec{v} ⋅ \vec{v}}$ is the length of the vector
15 Distance between vectors
15.1 We are using vectors to represent points in space, so we will compute the distance between the points $V$ and $W$ by computing $\sqrt{(\vec{v}-\vec{w})⋅ (\vec{v}-\vec{w})}$. This dot product magic just follows from the Pythagorean theorem.
16 Vectors in Ruby (components)
16.1 Now that we have a model of space, we can start writing some ruby code
websocketd for piping STDOUT to a WebSocket server
32 Fork off an HTTP server
rd,wt=IO.pipepid=forkdord.closeserver=WEBrick::HTTPServer.new({:Port=>PORT,:BindAddress=>"localhost",:StartCallback=>Proc.new{wt.write(1)# write "1", signal startwt.close}})trap('INT'){server.stop}server.mount("/",WEBrick::HTTPServlet::FileHandler,'./examples')server.startend# ...
33 Shell out to websocketd
33.1 websocketd converts standard input and output into a fully functioning websocket server, so we can just puts out the universe state
examples=["binary.rb","ternary.rb","random.rb","figure_eight.rb"]index=ARGV.last.to_i# Shell out to websocketd, block until program finishessystem("bin/websocketd \ -port=8080 \ ruby #{examples[index]}")Process.kill('INT',pid)# kill HTTP server in child process
34 Binary Star system
34.1 Our first application is going to be simulating a binary star system, with two equal-mass stars
35 Find initial conditions
35.1 The two bodies will be traveling in uniform circular motion, so the following relation holds:
36 Given the masses and the distance $r$, we can figure out $a$:
37 Substituting a back in to get $v$
38 Run simulated binary star system
38.1 Pause to run simulations
39 The Three Body Problem
39.1 With only two bodies, it turns out to be possible to solve the equations of motion for all time, exactly.
39.2 With three or more bodies, it is in general impossible
40 However
40.1 The three body problem has been studied since 1747, and there are some well known examples
41 The “Figure Eight” Three Body Orbit
41.1 The paper “A remarkable periodic solution of the three-body problem in the case of equal masses” by Alain Chenciner and Richard Montgomery works out an orbit that looks like this: