Tying knots with reflecting lightrays Let a lightray bounce around inside a cube whose faces
are (internal) mirrors.
If its slopes are rational, it will eventually form a cycle.
For example, starting with a point $p_0$ in the interior
of the $-Y$ face of an axis-aligned cube, and initially heading in a direction
$v_0=(1,1,1)$, the ray will rejoin $p_0$ after 5 reflections,
forming a hexagon.
The figure below shows a more complicated 16-cycle.

Assume that $p_0$ and $v_0$ are chosen so that
(a) the ray never directly hits an edge or corner of the cube,
and (b) the ray path never self-intersects inside the cube.

Can every knot type be realized by a lightray reflecting inside in a cube?

The figure above is an unknot.
I believe (but am not certain) the 31-cycle below is knotted:

          

Any such knotted path is a stick representation of the knot,
but perhaps the many unsolved problems in stick representations
are not relevant to this situation.
My question is related to the probability of random knots
forming under various models, but usually those models are
aimed at polymers or DNA.  I have not seen this lightray model
explored, but would be interested to know of related models.
The choice of $(p_0,v_0)$ allows considerable freedom to "design"
a knot, but it seems difficult to control the structure of the path
to achieve a particular result.
I've explored tiling space by reflected cubes so
that the lightray may be viewed as a straight segment between
two images of $p_0$, but this viewpoint is not yielding
me insights.
If anyone has ideas, however partial, I would appreciate hearing them.
Thanks!
Edit1 (15Sep10).
I have not been able to yet access the
Jones-Przytycki paper that Pierre cites, but knowing the
keywords he kindly provided, I did
find related work by
Christoph Lamm
("There are infinitely many Lissajous knots"
Manuscripta Mathematica
93(1): 29-37
(1997))
that provides useful information:

*

*Theorem: Billiard knots in a cube are isotopic to Lissajous knots.


*As Pierre said, many knots are unachievable in these models.  In particular,
algebraic knots cannot be achieved.
The technical result is this.
Theorem: The Alexander polynomial of a billiard knot is a square
mod 2.


*In 1997, there were several intriguing open problems, including
these two. (a) Is every knot a billiard knot in some convex polyhedron?
(b) Can the unknot be achieved in every convex polyhedron that supports periodic paths?
Edit2 (15Sep10). Here is a little more information on open problems ca. 2000,
found in a list by Jozef H. Przytycki in the book that resulted from
Knots in Hellas '98:

*

*Is there a manifold that supports every knot?
(By "supports every knot" he means there is a billiard path isotopic to every knot type.)


*Is there a finite polyhedron that supports every knot?
There apparently is an "infinite polyhedron" that supports every knot.


*More specifically, is there a convex polyhedron that supports every knot? (This is 3(a) above.) [See Bill Thurston's correction below!]


*Even more specifically, is every knot supported by one of the Platonic solids?
I have not been successful in finding information on this topic later than 2000.
If anyone knows later status information, I would appreciate a pointer.  Thanks for the interest!
Edit3 (5Jul11).
The question has been answered (affirmatively) in a paper by
Pierre-Vincent Koseleff and Daniel Pecker
recently (28Jun11) posted to the arXiv:
"Every knot is a billiard knot":

"We show that every knot can be realized as a billiard trajectory in a convex prism. ...
Using a theorem of Manturov [M], we first prove that every knot has a diagram which is a star polygon.
[...Manturov’s theorem tells us that every knot (or link) is realized as the closure of a quasitoric braid...]
Then, perturbing this polygon, we obtain an irregular diagram of the same knot. We deduce that it is possible to suppose that 1 and the arc lengths of the crossing points are linearly independent over $\mathbb{Q}$. Then, it is possible to use the classical Kronecker density theorem to prove our result."

Edit4 (4Oct11).
A new paper was released by Daniel Pecker, "Poncelet's theorem and Billiard knots," arXiv:1110.0415v1. The context is that, earlier, "Lamm and Obermeyer proved that not all knots are billiard knots in a cylinder," and Lamm conjectured an elliptic cylinder would suffice.
Here is the abstract:

Let $D$ be any elliptic right cylinder. We prove that every type of knot can be realized as the trajectory of a ball in $D$. This proves a conjecture of Lamm and gives a new proof of a conjecture of Jones and Przytycki. We use Jacobi's proof of Poncelet's theorem by means of elliptic functions.

Edit5 (13Nov12).
The Pecker paper cited above is now published:
Geometriae Dedicata,
December 2012, Volume 161, Issue 1, pp 323-333.
 A: This is my understanding of Bill Thurston's ingenious idea:

          

I selected the initial ray to drift upward slowly, and did not run the simulation so far as to reflect off the ceiling.
As per Bill's request, here is an overhead view of that rightmost image above, with rays colored
to more clearly distinguish the reflecting planes.

          
A: Coming back to the sawteeth described by Bill: many (or all) crossing patterns can be generated if the parameters x of the crossings are rationally independent (or 'independent enough'). In particular, symmetries in the x-y-shadow must be avoided. 
A related article of mine on 'Fourier knots' discusses the question whether certain billiard curves in 2 dimensions allow the construction of all knots if the z-movement is arbitrary (I focus on the square and the circle). I will send this article to anyone who is interested (the 5 page article is from 1998 and part of my PhD thesis, that's the reason why it is not published elsewhere).
My favorite billiard room to generate all knots is the prism over any ellipse. In this case the x-y-paths are asymmetrical enough, but it would be necessary to prove that the coordinates of the crossings are, e.g., rationally independent. - Christoph Lamm
A: These knots seem to be called billiard knots in the literature. They coincide with Lissajous knots as shown by Jones and Przytycki in "Lissajous knots and billiard knots", Banach center Publications 42, 145-163 (1998). Lissajous knots are knots admitting a parametrization of the form $(\cos(n_x t + d_x), \cos(n_y t + d_y), \cos(n_z t + d_z))$. There are strong constraints on such knots (see the wikipedia), and for example no torus knot can be Lissajous.
A: This started as a comment, but outgrew the space.
Edit1, 3(a) vs Edit2, (3) on their face sound like different questions to me: 
(forevery knot is there a polyhedron), vs. (is there a polyhedron such that forevery knot) 
for which the knot is a billiard trajectory.
From a solution to Edit1, 3(a), you can get a convex set that works as in Edit2,3, but I don't see why a polyhedron would be implied. If 3(a) is true, then take a countable sequence of polyhedra together with billiard trajectories that cover all possible knot types.
Take a sequence of points on $\mathbb {RP}^2$ with disjoint neighborhoods of radius $\epsilon_i$.
Now compress the $i$th polyhedron by an affine map until the points of contact with the knot are nearly on a pair of parallel planes with tangent planes nearly parallel to that plane, and graft this in to $S^2$ near the pair of antipodal points representing the $i$th point chosen in $\mathbb{RP}^2$.
There is an implication that forevery knot there is a convex set ... implies forevey knot there is a polyhedron ... . A convex set that works for a knot, or finite collection of knots, can be modified to a polyhedron: just use the tangent planes at the points of contact to delineate a polyhedron.
My guess is that: 3(a) is true. I'm imagining taking a picture of a knot as a plait, and then constructing a convex tube just for it, where the knot mostly bounces up and down toward you and away from you, but bends and crosses where necessary. If I get a concrete construction, I'll fill in specifics --- currently it's just an idea.  I would also guess that no single polyhedron will work for all knots. It's an interesting challenge to try to describe special properties of knots associated with a specific polyhedron. 
Added: Plan for realizing all knots with one polyhedron
On further reflection (ha ha), my guess is that we can construct a single polyhedron that will realize all possible knot types. I will sketch the plan --- others are welcome to join in to either fill it in, or  refute it.
Update: See Joseph O'Rourke's answer for pictures.
To start, think of a planar polygon that is a slightly modified square.  In a square, there are trajectories that bounce back and forth nearly perpendicular to two parallel walls, gradually proceeding down the length.  When they reach the end, they glance across a wall and start a journey back.
Now modify the square by beveling one corner at a 45 degree angle, so that when trajectories reach the cutout, they strike at an angle just less than 45 degrees from perpendicular, so they turn nearly 90 degrees and start  in the nearly perpendicular direction, with a slight drift away from the nearby side. Trajectories bounce back and forth for a time between the two major directions, hitting the bevel every other turn, until they reach the end of the bevel, when they start a journey crisscorssing between the second pair of parallel sides.
Put another 45 degree bevel at the opposite corner, so now there are periodic trajectories with this qualitative description with arbitrarily many crossings between pairs of parallel sides.
I have a strong hunch that any knot type can be arranged in a form that has projection to one of these trajectories, just making use of the main weaving part for creating the knot type, but I haven't thought through the details.  Let's suppose so, or at least suppose we have a knot that has a weaving style projection.
Now, make a cylinder with the hexagon as above as base, adding two new faces perpendicular to the faces of the cylinder.  It is best to visualize it as a thin plate, although logically it is irrelevant how high it is.   Trajectories in the cylinder map to trajectories in the hexagon.   For each closed trajectory $\gamma$ in the hexagon and for each integer $N$, there is a circle's worth of trajectories  in 3 dimensions that project to $\gamma$ and hit the floor and ceiling exactly $N$ times (at regular intervals). The extra circle parametrizes their phase.
Lemma :  for any $\gamma$ and any specification of crossing information, there is a billiard trajectory that projects to $\gamma$ and has the given types of crossings.
I suspect this is probably reflexive knowledge to some group of mathematicians. It's saying that if you take a collection $H$ of numbers in the interval (the vertical heights), then look at their orbit under the semigroup $\{ N x + b\}$ generated by translations and multiplication by integers, then the ordering of Sawtooth(Nx + b)(H) can be anything.
I think a stronger fact is true the images should be dense in the set of $|H|-tuples$ in the interval.
If this plan holds up, then every knot type can be realized in this 8-faced polyhedron.
