{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Classical Billiards on a Square Table

\n", "\n", " A billiard ball bounces around classically on a square table and is visuallizes with Vpython. \n", " To be compared with the quantum version of this program \"SqBilliardQM\"." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glow.min\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glowcomm\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/jquery-ui.custom.min\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glow.min\"], function(){console.log(\"GLOW LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glowcomm\"], function(){console.log(\"GLOWCOMM LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/jquery-ui.custom.min\"], function(){console.log(\"JQUERY LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\"\"\" From \"COMPUTATIONAL PHYSICS\" & \"COMPUTER PROBLEMS in PHYSICS\"\n", " by RH Landau, MJ Paez, and CC Bordeianu (deceased).\n", " Copyright R Landau, Oregon State Unv, MJ Paez, Univ Antioquia, \n", " C Bordeianu, Univ Bucharest, 2021. \n", " Please respect copyright & acknowledge our work.\"\"\"\n", "\n", "# SqBillardCM.py: Animated classical billiards on square table\n", "\n", "% matplotlib notebook\n", "from vpython import *\n", "\n", "dt = 0.01; Xo = -90.; Yo = -5.4; v = vec(13.,13.1,0)\n", "r0 = r= vec(Xo,Yo,0); eps = 0.1; Tmax = 500; tp = 0\n", "scene = display(width=500, height=500, range=120,\\\n", " background=color.white, foreground=color.black)\n", "table = curve(pos=([vec(-100,-100,0),vec(100,-100,0),vec(100,100,0),\n", " vec(-100,100,0),vec(-100,-100,0)]))\n", "ball = sphere(pos=vec(Xo,Yo,0),color=color.red, radius=3,make_trail=True)\n", "\n", "for t in arange(0,Tmax,dt):\n", " rate(5000) \n", " tp = tp + dt \n", " r = r0 + v*tp\n", " if(r.x>= 100 or r.x<=-100): # Right and left walls\n", " v = vector(-v.x,v.y,0)\n", " r0 = vector(r.x,r.y,0)\n", " tp = 0\n", " if(r.y>= 100 or r.y<=-100): # Top and bottom walls\n", " v = vector(v.x,-v.y,0)\n", " r0 = vector(r.x,r.y,0)\n", " tp = 0\n", " ball.pos=r " ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }