In the custom page, you declear variable as local scope:

double deltax = x[1]-x[0], deltay = y[1]-y[0]; //
double deltaVx = vx[1]-vx[0], deltaVy = vy[1]-vy[0];
double distance = Math.sqrt(deltax*deltax+deltay*deltay)-diameter/2*2;  //   

So deltax,deltaVx and distance are only available in the custom page.

If you want to use those variable (or any variable globally). Define variable in the [b]Variable[/b] tabs.
And you can access all variables defined in the Variable tabs anywhere in the ejs program.

So you need to define deltax,deltaVx and distance , and change the above code to
deltax = x[1]-x[0], deltay = y[1]-y[0]; //
deltaVx = vx[1]-vx[0], deltaVy = vy[1]-vy[0];
distance = Math.sqrt(deltax*deltax+deltay*deltay)-diameter/2*2;  //   

And you can assign the above variables to any view element to find out their value!