Professional Documents
Culture Documents
Luis Santos
Sheet 5 (Deadline: 30.01.23), Total: 11 points
The billiard is characterized by the points (x, y) that fulfill y 2 < F (x), with
In order to study the properties of these billiards, we need first a numerical code that
simulates the dynamics of a point-like ball inside the billiard, and in particular how it
bounces against the walls. These can be accomplished by following these steps:
• (i) Let us consider that at time tn the particle is in the position ~rn = (xn , yn ),
and moves with velocity ~v = (vx , vy ). We assume from now one that |~v | = 1, and
that only the orientation of the velocity changes (when the particle bounces at the
boundary wall).
• (ii) Let us consider a time step ∆t (take the step sufficiently small, e.g. ∆t = 0.001).
After one time step the new position is xn+1 = xn + vx ∆t, yn+1 = yn + vy ∆t.
• (iii) After every step, check if the particle has hit the billiard. The particle has hit
the billiard at step n, if yn2 < F (xn ), but at step n + 1, yn+1
2
> F (xn+1 ) (if this is not
the case, you just repeat step (ii) until hitting the boundary). If ∆t is sufficiently
small, one can assume that (xn , yn ) is a point on the boundary. (Comment: You can
proceed in this way, although there are alternatives to the use of a very small ∆t for
all iterations, since a very small ∆t is only needed at the very boundary, perhaps
you can think of a more economic way, like reducing ∆t once you hit the boundary,
and then refine ∆t only when that occurs.).
• (iv) Once the contact point at the boundary is reached, one needs to evaluate the
bounce. We assume mirror reflection, this means that at the contact point, the
projection of the velocity perpendicular to the normal vector ~n of the boundary at
the contact point is conserved, whereas the one parallel to ~n changes sign (see the
figure below). This means that, if before the bounce the velocity is ~v , then after the
bounce, the particle has the velocity ~vB = ~v − 2(~v · ~n)~n, where the normal vector at
the contact point (x, y) is given by:
Using these expressions you should be able to evaluate the velocity after the bounce.
• (v) Now you know the new velocity of the particle. Go back to (i) and repeat.
Starting with some initial condition (x0 , y0 ) with velocity (vx (0), vy (0)), you can then find
the trajectory of the particle.
Once you have implemented the code, you will be ready to study the dynamics in the
billiard.
• (2 P) (a) Let us consider first the simplest case, namely a circular billiard (M = 0).
Let us assume as initial condition (x(0), y(0)) = (−1, 0), with velocity vx (0) = cos φ,
vy (0) = sin φ, with φ/π = 1/3. Plot the trajectory x(t), v(t) until the bounce number
50. (Note: You should see that the particle touches the boundary only at 6 points,
always the same points. If you do not get only 6 points, it is possibly because your
∆t is not small enough, and hence your bounces occur a little bit off the boundary).
√
What happens if you take φ/π an irrational number, e.g. φ/π = 1/ 2? The analysis
is very much enlightened if for each contact point (x, y) of the trajectory you evaluate
s = atan(y/x) (note that s ∈ [0, 2π)). If you plot the histogram of √ the s values, then
you would see a very clear difference between φ/π = 1/3 and 1/ 2. Interprete your
results using the notion of ergodicity.
%We define the position variables
x=[];
y=[];
s=[];
%We define the velocity with modulus 1 and ask the user for its direction (the angle).
phi=input('Introduce the angle of the velocity:');
v=[cos(phi),sin(phi)];
%We define the time steps, and ask the user for the value of M.
deltaT=0.0001;
bounce=0;
M=input('Introduce the value for the distance M');
i=0;
%We use a loop 'while' so as we can do as many iterations as we need for
%having n number of bounces
while bounce<50
i=i+1;
%We use loops 'if' for determine in which of the three regions is our
%ball; and after that, under the condition y^2<F(x), we do an iteration
%with the same velocity or we do the reflexion in the boundary.
if x(i)>M/2
if y(i)^2<1-(x(i)-M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)-M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
%Each time the ball bounces we count it so that we can control the number
%of iterations.
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif x(i)<-M/2
if y(i)^2<1-(x(i)+M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)+M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif abs(x(i))<=M/2
if y(i)^2<1
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[0,-y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
end
end
figure
hold on
plot(x,y);
title('Stadion billiard');
xlabel('Position x');
ylabel('Position y');
hold off
figure
hold on
histogram(s,16,'facecolor','b');
title('Histogram s=atan(y/x) at the contact points.')
hold off
%We define the position variables
clear all
clc
x=[];
y=[];
s=[];
%We define the velocity with modulus 1 and ask the user for its direction (the angle).
phi=input('Introduce the angle of the velocity:');
v=[cos(phi),sin(phi)];
%We define the time steps, and ask the user for the value of M.
deltaT=0.0001;
bounce=0;
i=0;
%We use a loop 'while' so as we can do as many iterations as we need for
%having n number of bounces
while bounce<bouncelimit
i=i+1;
%We use loops 'if' for determine in which of the three regions is our
%ball; and after that, under the condition y^2<F(x), we do an iteration
%with the same velocity or we do the reflexion in the boundary.
if x(i)>M/2
if y(i)^2<1-(x(i)-M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)-M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
%Each time the ball bounces we count it so that we can control the number
%of iterations.
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif x(i)<-M/2
if y(i)^2<1-(x(i)+M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)+M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif abs(x(i))<=M/2
if y(i)^2<1
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[0,-y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
end
end
figure
hold on
plot(x,y);
title('Stadion billiard');
xlabel('Position x');
ylabel('Position y');
hold off
figure
hold on
histogram(s,16,'facecolor','b');
title('Histogram s=atan(y/x) at the contact points.')
hold off
%STADION BILLIARD
clear all
clc
format long
x=[];
y=[];
s=[];
%We define the velocity with modulus 1 and ask the user for its direction (the angle).
phi=input('Introduce the angle of the velocity:');
v=[cos(phi),sin(phi)];
%We define the time steps, and ask the user for the value of M.
deltaT=0.000001;
bounce=0;
i=0;
%We use a loop 'while' so as we can do as many iterations as we need for
%having n number of bounces
while bounce<bouncelimit
i=i+1;
%We use loops 'if' for determine in which of the three regions is our
%ball; and after that, under the condition y^2<F(x), we do an iteration
%with the same velocity or we do the reflexion in the boundary.
if x(i)>M/2
if y(i)^2<1-(x(i)-M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)-M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
%Each time the ball bounces we count it so that we can control the number
%of iterations.
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif x(i)<-M/2
if y(i)^2<1-(x(i)+M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)+M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
elseif abs(x(i))<=M/2
if y(i)^2<1
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[0,-y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s=[s,atan(y(i)/x(i))+pi()];
end
end
end
figure
hold on
plot(x,y);
title('Stadion billiard');
xlabel('Position x');
ylabel('Position y');
hold off
figure
hold on
histogram(s,16,'facecolor','b');
title('Histogram s=atan(y/x) at the contact points.')
hold off
%We define the position where the particle ends for doing the reversal, as
%well as the value of s at this position.
x_final=x(i);
y_final=y(i);
s_initial=s(1)
v_final=v;
format long
x=[];
y=[];
s2=[];
%we use the previous final conditions as intial ones for the reversal.
x(1)=x_final;
y(1)=y_final;
deltaT=0.000001;
bounce=0;
i=0;
%We use a loop 'while' so as we can do as many iterations as we need for
%having n number of bounces
%To recover exactly the reversed dynamics, we have to consider one less
%bounce as we start the motion just after the bounce on the previous code.
while bounce<bouncelimit-1
i=i+1;
%We use loops 'if' for determine in which of the three regions is our
%ball; and after that, under the condition y^2<F(x), we do an iteration
%with the same velocity or we do the reflexion in the boundary.
if x(i)>M/2
if y(i)^2<1-(x(i)-M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)-M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
%Each time the ball bounces we count it so that we can control the number
%of iterations.
bounce=bounce+1;
s2=[s2,atan(y(i)/x(i))+pi()];
end
elseif x(i)<-M/2
if y(i)^2<1-(x(i)+M/2)^2
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[x(i)+M/2,y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s2=[s2,atan(y(i)/x(i))+pi()];
end
elseif abs(x(i))<=M/2
if y(i)^2<1
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
else
n=-[0,-y(i)];
v=v-2*(dot(v,n))*n;
x(i+1)=x(i)+v(1)*deltaT;
y(i+1)=y(i)+v(2)*deltaT;
bounce=bounce+1;
s2=[s2,atan(y(i)/x(i))+pi()];
end
end
end
figure
hold on
plot(x,y,'r');
title('Stadion billiard');
xlabel('Position x');
ylabel('Position y');
hold off
figure
hold on
histogram(s,16,'facecolor','r');
title('Histogram s=atan(y/x) at the contact points.')
hold off
s_final=s2(bouncelimit)