145

Suppose Mario is walking on the surface of a planet. If he starts walking from a known location, in a fixed direction, for a predetermined distance, how quickly can we determine where he will stop?

enter image description here

More formally, suppose we are given a convex polytope $P$ in 3-space, a starting point $s$ on the surface of $P$, a direction vector $v$ (in the plane of some facet containing $p$), and a distance $\ell$. How quickly can we determine which facet of $P$ Mario will stop inside? (As a technical point, assume that if Mario walks into a vertex of $P$, he immediately explodes; fortunately, this almost never happens.)

Or if you prefer: suppose we are given the polytope $P$, the source point $s$, and the direction vector $v$ in advance. After preprocessing, how quickly can we answer the question for a given distance $\ell$?

It's easy to simply trace Mario's footsteps, especially if $P$ has only triangular facets. Whenever Mario enters a facet through one of its edges, we can determine in $O(1)$ time which of the other two edges he must leave through. Although the running time of this algorithm is only linear in the number of edge-crossings, it's unbounded as a function of the input size, because the distance $\ell$ could be arbitrarily larger than the diameter of $P$. Can we do better?

(In practice, the path length isn't actually unbounded; there is a global upper bound in terms of the number of bits needed to represent the input. But insisting on integer inputs raises some rather nasty numerical issues — How do we compute exactly where to stop? — so let's stick to real inputs and exact real arithmetic.)

Is anything nontrivial known about the complexity of this problem?

Update: In light of julkiewicz's comment, it seems clear that a real-RAM running time bounded purely in terms of $n$ (the complexity of the polytope) is impossible. Consider the special case of a two-sided unit square $[0,1]^2$, with Mario starting at $(0,1/2)$ and walking in direction $(1,0)$. Mario will stop on the front or the back of the square depending on the parity of the integer $\lfloor \ell \rfloor$. We can't compute the floor function in constant time on the real RAM, unless we're happy equating PSPACE and P. But we can compute $\lfloor \ell \rfloor$ in $O(\log \ell)$ time by exponential search, which is an exponential improvement over the naive algorithm. Is time polynomial in $n$ and $\log \ell$ always achievable?

Jeffε
  • 23,129
  • 10
  • 96
  • 163
  • A variation: Decide whether Mario will explode while he is traveling for the distance l. This may be as hard as your problem (and if it is, it is a nice decision problem), but I do not know. – Tsuyoshi Ito May 02 '11 at 00:26
  • 6
    I thought of a simpler problem, that is: we have a plain polygon and a beam of light traveling from a given point. When it reaches an edge it just gets mirrored. We want to know where the beam will end its travel after the given distance. It could (almost) be reduced to this one, by taking a polytope that is a prism of a very small height with the top and bottom sides in a shape of a given polygone. Maybe solving this first could help. – julkiewicz May 02 '11 at 00:57
  • @Julkiewicz: A two-sided planar polygon is a degenerate convex polytope; it's the limit of a prism of height ε as ε goes to zero. So yes, your problem is a special case of Mario's. – Jeffε May 02 '11 at 02:27
  • 3
    “[T]ime polynomial in n and log l” does not make sense to me. If it depends on l, it must also depend on the coordinates of P, and if you add log of all the numbers in the input, that is exactly the number of bits needed to represent the input when the input coordinates are restricted to integers. I think that you are looking at the time complexity on a real RAM when the input is given as a bit string. – Tsuyoshi Ito May 02 '11 at 11:21
  • 4
    Even deciding if Mario ever hits a vertex (independent of $\ell$) seems difficult. I think here we run into the many unknowns in the area of billiard dynamics. – Joseph O'Rourke May 03 '11 at 11:10
  • A simpler description: given a string of length $l$, fixed to a point on the surface of the polyhedron, where will the other string be when it is stretched on the surface along a particular direction? – Rob May 03 '11 at 15:07
  • @Tsuyoshi: Yes, you're right. So perhaps the right goal is polynomial in $n$ and $\log \Delta$, where $\Delta$ is the ratio of $\ell$ and the length of the shortest edge in $P$. Or something. – Jeffε May 03 '11 at 22:08
  • For each edge it's possible to create a sorted set of sorted sets of polygons, in which Mario will travel depending on the direction he is on current edge. It's a binary search to find a set based on the edge position, a binary search to find a polygon sequence in a set based on current direction, and it's a binary search to find the polygon, at which Mario stops, if current polygon set can exhaust the path, or the edge at which the next step should be taken. The complexity of this algorithm is based on the 3 binary searches and all they depend on maximum length of precomped polygon sequences. – George Polevoy May 13 '11 at 11:50
  • Wouldn't it be more logical to determine the radius of the galaxy first? The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical "triangles". – gotnull Sep 07 '11 at 04:59
  • But the triangles in my proposed problem are flat, not spherical. – Jeffε Sep 07 '11 at 14:10
  • 3
    Not really related, but this paper about the NP-Completeness of Super Mario is really amazing: http://arxiv.org/pdf/1203.1895v1.pdf – Lamine Mar 16 '12 at 13:59
  • What does “equating #PSPACE and P” mean? That looks like a type error to me. – Tsuyoshi Ito Jun 09 '12 at 00:44
  • @TsuyoshiIto: Follow the link. In a RAM model of computation that supports arithmetic operations on arbitrary integers in constant time, one can solve any problem in #PSPACE in polynomial time. – Jeffε Jun 09 '12 at 03:14
  • Did you follow the link? – Tsuyoshi Ito Jun 09 '12 at 03:40
  • Thanks for fixing the link. Sorry for asking without reading the cited papers, but I cannot follow the logic stated in the page. If QBF can be solved in polynomial-time using the model, isn’t it obvious that #SAT can be also solved, because QBF is PSPACE-complete and each bit of the answer of #SAT is in PP and hence in PSPACE? Also, I do not think that the link talks about #PSPACE. – Tsuyoshi Ito Jun 09 '12 at 11:50
  • The techniques used to solve #SAT and QBF in polynomial "time" can be combined fairly easily to solve #QBF in polynomial "time". (I didn't realize this until after I posted the linked text.) – Jeffε Jun 09 '12 at 12:56
  • I do not know how to define #QBF. Is it more difficult than QBF? If you define #PSPACE as the class of counting problems associated with polynomially-balanced, PSPACE-decidable relations, then I think that it is equivalent to FPSPACE, the function version of PSPACE, unlike the case of #P. – Tsuyoshi Ito Jun 09 '12 at 18:59
  • 1
    Also, my original concern still remains: P is a class of decision problems. If #PSPACE is a class of functions, they are never equal because they have different types. – Tsuyoshi Ito Jun 09 '12 at 19:01
  • In your update, a reference to $\ell$ is missing - how does it show up in the unit square problem ? – Suresh Venkat Jun 10 '12 at 07:04
  • The problem seems to be easy if one can cut the polytope along some edges, unfold it into plane, and then this unfolded figure tiles the plane (i.e. covers the whole plane without overlap), like in your two sided square example. Otherwise, one needs branching, e.g. to attach another plane polygon which may depend on the direction. It may be possible to use symmetries, but if symmetries are broken, e.g. all facets has different symmetry, it is not clear at all how to use them. – mkatkov Nov 12 '12 at 09:59
  • long wondering/curious, can anyone explain why this question is so highly rated? it has interesting aspects but just doesnt seem to be connected to any major complexity theory problems or famous open conjectures etc... – vzn Jun 06 '13 at 15:26
  • 10
    "Maybe that's why it's so highly rated," said someone completely apathetic about complexity theory. – Jeffε Jun 07 '13 at 03:00
  • 1
    @mkatkov I was also thinking that unfolding may improve the problem, but then I found this : G.C. Shephard, Convex Polytopes with Convex Nets. Math. Proc. Camb. Phil. Soc., 78:389-403 (1975), and apparently the question "Can every convex polyhedron be cut along its edges and unfolded flat to a single, non-overlapping, simple polygon," i.e., a single connected flat component is still open! – daaxix Jul 29 '14 at 20:39
  • 2
    idea for bridge theory: there is some deep math research into a field known as "rational billiards" which looks at the trajectory of a billiard ball on polygonal tables which seems similar, & also looks at periodic tilings of the polygonal table surfaces. suspect there may be some connections to the Super Mario Galaxy problem... ran across some of this reading about new Fields medalist winner Mirzakhani... – vzn Aug 13 '14 at 16:11
  • this paper was just found by EJS & seems closest published research to the problem so far. THE DISCRETE GEODESIC PROBLEM / Mitchell, Mount, Papadimitriou – vzn May 31 '16 at 22:45
  • I'm new to this site from stack exchange and I very much like this problem. I would leave an answer on how I would treat or tackle this problem but my reputation isn't high enough yet. – Francis Cugler Jul 25 '16 at 12:33
  • do you have planet speed at time ? – mussdroid Aug 04 '16 at 04:55
  • This is not an algorithm... For any face the trajectory is coming from some edge and is going to another edge. In at most the N edge crossings one of the faces will be visited twice (N is the number of faces). One can color all trajectories leading from this face to itself. Then repeat for uncolored region. There would be long precomputing, but you will end up with edge maps showing distances for each colored regions. Than I guess one can use exponentiation algorithm for same face travel. – mkatkov Jan 25 '17 at 19:06
  • I am pretty much a layman, but why is this so hard? I'm thinking one could A) "unwrap" the planet, make the surface repeat somehow and just walk a straight line on the surface B) We can do calculations with lines on curved surfaces like a sphere, no? Or calculations with lines on a surface of, say, cube? Why is it that we apparently can't construct a line starting from some point on a sphere or a cube, make it certain length while wrapping around the object and figure out where the end point of that line is? – Swiffy Sep 09 '22 at 08:56
  • @Swiffy The question is not whether it can be done at all; the brute-force tracing procedure you described works just fine. The question is whether it can be done faster than that. Do we really need to separately consider each time Mario crosses over an edge of the polyhedron? Note that if we somehow know in advance that Mario doesn't cross his own path, we can beat the brute force algorithm! – Jeffε Sep 09 '22 at 23:31

2 Answers2

9

This problem is very very difficult. We could simplify it to make it easier, as follows.

  1. We can add the assumption that the angle sum about every vertex of the polytope $P$ is a rational multiple of $\pi$. This gets rid of most "polytopes" but there are still many interesting possibilities: for example, the platonic solids.

  2. We can assume that the polytope is not truly three-dimensional, but instead is the "double" of a polygon; this looks a bit like a pillowcase. We can simplify even further and suppose that the polygon has equal and parallel sides; for example a square, as in the game Astroids.

If we make both of these assumptions then there is a large theory. (Finding an $O(\log(\ell))$ algorithm for the square is a difficult exercise involving the continued fraction expansion of the angle of Mario's path. To achieve a similar result for the regular octagon is possible but harder. The solutions for the square and the octagon involve thinking about how to efficiently encode a "cutting sequences for a geodesic on a translation surface". Most other rational polygons will quickly lead to open problems.) An initial reference, which includes a further reference to Caroline Series's discussion of the square torus, are these talk slides by Diana Davis.

If we do not assume rationality, but do assume that the polytope is the double of a polygon, then we are discussing the theory of "cutting sequences in irrational billiards". It seems that essentially nothing is known here; for example see the final sentence of this talk by Corinna Ulcigrai.

If we make neither assumption, well, I can't think of anything in the literature.

Finally - I'll guess that there is an $O(\log(\ell))$ solution to the Super Mario Galaxy problem for the platonic solids. This is a good problem for a graduate student getting started in rational billiards. For example, the case of the dodecahedron "should" follow from Diana Davis's thesis. (But start with the tetrahedron - that will follow from an analysis of cutting sequences for the hexagonal torus.)

Sam Nead
  • 613
  • 4
  • 10
0

I think you can do better than linear. I'm new to theoretical computer science, so forgive me if this is rubbish.

Some general ideas (of varying value):

  • If we give each facet a symbol, Mario's orbit over them can be described as a string, where the final symbol in the string is the answer.
  • We can assume without loss of generality that Mario starts on an edge (just walk backwards and extend l to the edge)
  • The 2D space of starting positions and angles can be partitioned by the next edge. So starting at edge a, x units from the bottom, with an angle of a, we end up in edge V after crossing one facet.
  • At that point we're at another edge with another orientation, so we can call the function recursively to subdivide the space into partitions of 2-symbol strings and so on.
  • At this point we're finished if we say that the space has to be discretized for the problem to be implemented on a TM. That means that every orbit must be periodic because there are only finitely many points on the discretized planet. We can calculate the function described above until we have orbits for all starting points and store this information. Then the problem becomes O(1).
  • Maybe that's a bit of a cop out. Some googling tells me that almost all billiard orbits inside rational convex polygons are periodic (ie. the periodic orbits are dense). So for a (say) square planets the same approach might work.
  • Another approach would be to consider the system as a generator/recognizer of strings (again by assigning each facet its own symbol). If the language has a known complexity class, that's your answer. If you broaden the family of polytopes to non-convex and any dimension, you may capture a very broad class of languages.

This doesn't really constitute an answer, but I need to get back to work. :)

Peter
  • 459
  • 4
  • 13
  • 10
    "At this point we're finished if we say that the space has to be discretized for the problem to be implemented on a TM. That means that every orbit must be periodic because there are only finitely many points on the discretized planet." You've just destroyed the interesting part of the problem. I do not want to assume the input is discrete; I want to solve the actual continuous problem, even though this requires an ideal computer that can do exact real arithmetic in constant time. In particular, Mario's path need not ever touch a vertex. – Jeffε Jan 10 '12 at 11:30
  • I figured that was too easy. You could do the continuous version on a finite machine, so long as the starting point and planet can be finitely described. You can just represent the path symbolically (mathematica-style). You only need to evaluate certain bounds to find which facet you end up in.

    If you can prove that the path is almost certainly periodic (as it is for billiards on rational convex polygons), you can still apply the same trick, but the result wouldn't be very practical.

    – Peter Jan 10 '12 at 11:45
  • 12
    Alas, generic geodesics on generic polyhedra are not periodic. (In particular, generic polygons are not rational.) – Jeffε Jan 10 '12 at 16:29
  • You (Peter) are, I think, referring to the paper "Periodic billiard orbits are dense in rational polygons". This does not mean that periodic paths are generic in rational polygons. In fact, there are only countable many periodic paths (up to parallelism) so they have no chance of being generic. – Sam Nead Oct 18 '15 at 10:03
  • In fact, in a "Veech" polygon the "uniquely ergodic" paths are full measure. So if we send Mario is an random direction, he will (a) never hit a vertex (as Jeffe says in the problem statement), (b) his path will never close up, and (c) at large scales, the sequence of visited faces will look random (due to a "weak mixing" property). This doesn't suggest a negative answer to the problem -- for example, the digits of pi also look random... – Sam Nead Oct 18 '15 at 10:04