{"id":155,"date":"2015-03-06T11:07:16","date_gmt":"2015-03-06T11:07:16","guid":{"rendered":"http:\/\/nbodyphysics.com\/blog\/?p=155"},"modified":"2015-03-17T10:23:21","modified_gmt":"2015-03-17T10:23:21","slug":"asteroids-on-a-torus","status":"publish","type":"post","link":"https:\/\/nbodyphysics.com\/blog\/asteroids-on-a-torus\/","title":{"rendered":"Asteroids on a Torus"},"content":{"rendered":"<div style=\"width: 625px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-155-1\" width=\"625\" height=\"352\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo1.mp4?_=1\" \/><a href=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo1.mp4\">http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo1.mp4<\/a><\/video><\/div>\n\n<p>One of the great things about meetups is their ability to generate weird idea exchanges. Late last year I demonstrated ThreeBody &#8211; another\u00a0of my oddball, limited appeal physics apps. I was mentioning that it might be fun to see what happens to the three body problem in a spherical space &#8211; since this would solve the &#8220;ejection to infinity&#8221; issue by removing infinity. This led to a discussion about the topology of games like asteroids where the top\/bottom and left\/right are wrapped. This mapping creates a space that is a topological torus. This was the spark I needed to think more carefully about what motion on a real torus would be like.<\/p>\n<p>I don&#8217;t need much of an excuse to think about an\u00a0odd physics scenario.\u00a0 My past includes time spent taking a break from the working world and doing a PhD involving\u00a0curved spacetimes. One of the problems that comes up in such studies as a way of sharpening skills is the study of motion on curved 2D surfaces. It is a great place to learn to use the mathematical machinery and intuitive enough that the answers can be visualized.<\/p>\n<p>This made me wonder how different a space shooter\u00a0would be if the physics of a torus was made &#8220;technically correct&#8221;\u00a0<a title=\"Futurama\" href=\"https:\/\/www.youtube.com\/watch?v=hou0lU8WMgo\">(the <em>best<\/em>\u00a0kind of correct)<\/a> . The result is a soon to be released game &#8220;Geodesic Asteroids&#8221; in which there is a dual view of the 3D motion and the 2D motion with the paths of objects moving in a &#8220;technically correct way&#8221;.<\/p>\n<h2>\u00a0The Torus<\/h2>\n<h2><a href=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-172\" src=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1-300x180.png\" alt=\"Torus1\" width=\"300\" height=\"180\" srcset=\"https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1-300x180.png 300w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1-1024x617.png 1024w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1-624x375.png 624w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/Torus1.png 1253w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h2>\n<p style=\"text-align: center;\">Figure 1: Torus coordinates<\/p>\n<p>First we need a mathematical description of the torus. It is a 2D surface so only two co-ordinates <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%28%5Ctheta%2C+%5Cchi%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"(&#92;theta, &#92;chi)\" class=\"latex\" \/> are needed to describe a point. If we think of the typical donut representation sitting on\u00a0the x, y plane then <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta\" class=\"latex\" \/> is the angle around the z-axis\u00a0(say from the line x=0) and <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cchi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;chi\" class=\"latex\" \/> is the angle around the cross section of the torus at a given <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta\" class=\"latex\" \/>. The radius of the center of the torus is <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"a\" class=\"latex\" \/> and the radius of the cross section is <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"b\" class=\"latex\" \/>.<\/p>\n<p>In the mathematics for a torus, everything can be described in terms of these co-ordinates, including the equations of motion that define how an object moves when there is no force on it. We are accustomed to thinking of the torus as a three dimensional object but exactly which three dimensional shape results is partly due to the choice made when we embed the surface in 3D. There is really no reason we have to do this but it can help our intuition. [Digression: It an interesting mathematical question about exactly how may dimension are required to embed an N dimensional surface, we are accustomed to N+1 for e.g. spheres and torii but this is <a href=\"http:\/\/en.wikipedia.org\/wiki\/Whitney_embedding_theorem\">not the general rule<\/a>!].<\/p>\n<p>In our case we pick a customary embedding:<\/p>\n<p>$$x = (a + b \\cos{\\chi}) \\cos{\\theta}$$<\/p>\n<p>$$y = (a + b \\cos{\\chi}) \\sin{\\theta} $$<\/p>\n<p>$$z = b \\sin{\\chi} $$<\/p>\n<p>This allows us to map <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%28%5Ctheta%2C+%5Cchi%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"(&#92;theta, &#92;chi)\" class=\"latex\" \/> into the x, y, z world co-ordinates the game will use and retain our intuitive picture of a torus.<\/p>\n<p>What about a 2D map of this torus? Here I elected to just use\u00a0<img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%28%5Ctheta%2C+%5Cchi%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"(&#92;theta, &#92;chi)\" class=\"latex\" \/> as pure 2D co-ordinates i.e. as if they were the displays &#8220;x and y&#8221;. I impose a slight twist that I&#8217;ll explain in a minute.<\/p>\n<h2>Motion on the torus<\/h2>\n<p>The embedding equation provides the world space position to show events on the torus. What equations should be used to calculate motion on the torus? The motion takes place <strong>on<\/strong> the torus so the description is\u00a0in terms of\u00a0\u00a0<img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%28%5Ctheta%2C+%5Cchi%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"(&#92;theta, &#92;chi)\" class=\"latex\" \/>. Here there is a departure from the usual\u00a0equations\u00a0that govern\u00a0games. In the\u00a0flat 3D game world x, y and z are independent and there is no need to worry about where in the space we are.\u00a0<img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=F%3Dma&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"F=ma\" class=\"latex\" \/> is the same at the origin as it is at any other point. On curved surfaces things are different. To make this clear lets consider a simpler 2D surface, the sphere, with longitude <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cphi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;phi\" class=\"latex\" \/> and latitude <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta\" class=\"latex\" \/>.<\/p>\n<p><a href=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/greatCircle.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-170\" src=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/greatCircle.png\" alt=\"greatCircle\" width=\"225\" height=\"225\" srcset=\"https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/greatCircle.png 225w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/greatCircle-150x150.png 150w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>As you know from looking at maps of airplane flights, the lines between points take what seem to be curves on the map. This is because the force-free (or geodesic) path that connects two points is a great circle. This means if you are in New York and head directly west the geodesic path must be a diameter of the circle and will carry you into the southern hemisphere until you are at the antipodal point directly opposite New York through the center of the earth. [Fun fact: very few places on land have an <a href=\"http:\/\/www.findlatitudeandlongitude.com\/antipode-map\/#.VNa4LlXF8Z0\">antipodal point on land<\/a>]. You started out with only a velocity in the <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cphi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;phi\" class=\"latex\" \/> direction but ended up on a trajectory for which <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta\" class=\"latex\" \/> also changed.\u00a0This means that the equations of motion are\u00a0coupled. The equation for the evolution of <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta\" class=\"latex\" \/> depends on the velocity in the <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cphi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;phi\" class=\"latex\" \/> direction. In the case of a sphere the equations for\u00a0force free motion are:<\/p>\n<p>$$a_{\\theta} =v_{\\phi} v_{\\phi} \\sin{\\theta} \\cos{\\theta} , \u00a0a_{\\phi} = \\frac{-2 v_{\\theta} v_{\\phi}}{\\tan{\\theta}} $$<\/p>\n<p>For a torus the equations are:<\/p>\n<p>$$a_{\\theta} = \\frac{2 \\sin{\\chi} v_{\\chi} v_{\\theta}}{b (a + b \\cos{\\chi})},\u00a0a_{\\chi} = &#8211; \\frac{2 \\sin{\\chi} v_{\\theta}^2}{(a + b \\cos{\\chi})} $$<\/p>\n<p>The good news is that on the torus the co-ordinates are well behaved. The expression are finite. (If you look at the equations for the sphere you&#8217;ll see it is possible for some values to be dividing by zero. Never a great idea. This is not a fundamental part of motion on a sphere, there is no special place where acceleration goes to infinity. It&#8217;s just a bad choice of co-ordinates and we need to choose a different origin in some case. It is quite usual to have to cover a surface with several co-ordinate patches. For the torus we are lucky that this is not needed.)<\/p>\n<h2>Where did those equations come from?<\/h2>\n<p>The equations for <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=F+%3D+m+a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"F = m a\" class=\"latex\" \/> on a curved surface come from a branch of mathematics known as differential geometry. &#8220;Differential&#8221; since it studies the behaviour of surfaces that are smooth enough that you can do calculus, i.e. no sudden steps or cusps. One of the new ideas that enters with differential geometry is that while you can do calculus at each point, you cannot directly compare the results of these calculations at\u00a0different points. This is because each point has its own tangent plane (more generally tangent space). As an object slides along the 2D surface the local co-ordinates of the object\u00a0change relative to the surface co-ordinates. Returning to our sphere example, if you initially were heading west from New York when your great circle crosses the equator you are no longer facing west BUT you did not turn, you were just following your geodesic path. Exactly what the geodesic path is and how it turns as you go is something that can be calculated for a surface.<\/p>\n<p>It&#8217;s not my goal to turn this post into a treatise on differential geometry. It is a very interesting subject and is the stage on which Einstein&#8217;s General Theory of Relativity takes place. All the introductory\u00a0GR texts start with some background in differential geometry and I find their approach more geared to my interest than the way math\u00a0books\u00a0approach the subject.\u00a0For those interested in a good introduction to the geodesics of the torus and an introduction to the basics of differential geometry, I recommend <a title=\"Torus Paper\" href=\"http:\/\/www34.homepage.villanova.edu\/robert.jantzen\/notes\/torus\/torusgeos.pdf\">Jantzen&#8217;s paper.<\/a>\u00a0My favourite intro GR book is Schutz&#8217;s &#8220;A First Course in General Relativity&#8221;<\/p>\n<h2>Differences between\u00a02D and 3D representations<\/h2>\n<p>A space game on a torus can be shown in 3D but it is also interesting to play the game on the 2D representation of the surface. Here the odd paths of the objects make the impact of the curved surface apparent. There are some compromises in mathematical purity that I\u00a0have made in the interests of actually finishing the game. The primary one is that the size of objects in the 2D and 3D view cannot be fully reconciled (more below).<\/p>\n<p>On the true mathematical surface the distance travelled as you walk around the outside diameter is different from the inside diameter. On the 2D map this\u00a0means that the top edge of the map should not be as wide as the middle. Our choice of a 2D map is therefore vulnerable to the an effect similar to that occurring on a Mercator projection of the Earth (Greenland is shown as far\u00a0too big). \u00a0I have chosen a simple scaling depending on the &#8220;latitude&#8221; <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cchi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;chi\" class=\"latex\" \/>. To continue this accuracy it is necessary to change\u00a0the horizontal size of the objects as they change latitude. I did put this in the game as an option &#8211; but the result is a bit odd looking. In normal play this mode is disabled &#8211; with the consequence that the objects on the screen are not exactly the correct size. The correct size is used for detecting bullet hits\u00a0and in some cases an apparent hit on the map is not a &#8220;real&#8221; hit.<\/p>\n<div style=\"width: 625px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-155-2\" width=\"625\" height=\"352\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo_weird.mp4?_=2\" \/><a href=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo_weird.mp4\">http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2015\/03\/geo_weird.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"line-height: 1.714285714; font-size: 1rem;\">True scaling leads to some weird paths in the map view. If an object is moving quickly in <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cchi&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;chi\" class=\"latex\" \/> the shrinking due to the scale factor can exceed motion towards the edge making it look as if the object backs up a bit before continuing on.<\/span><\/p>\n<p>Geodesic Asteroids is available\u00a0on Blackberry, iOS and Android. It has been great fun to think about and use the geodesic math I learned long ago. It is also the first time I have written a more &#8220;video game&#8221; style game. Hope you&#8217;ll find it interesting.<\/p>\n<p>[social4i size=&#8221;large&#8221; align=&#8221;float-right&#8221;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the great things about meetups is their ability to generate weird idea exchanges. Late last year I demonstrated ThreeBody &#8211; another\u00a0of my oddball, limited appeal physics apps. I was mentioning that it might be fun to see what happens to the three body problem in a spherical space &#8211; since this would solve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-software-development"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3pCRa-2v","_links":{"self":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":16,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/155\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}