{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# parabolic reflector\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as plt\n\nfig, ax = plt.subplots(1,1)\n\n\ndef y(x):\n return x**2/2\n\ndef df(x,y):\n return np.array([-x, 1])\n\n#x0 = 1.5\nfor x0 in np.linspace(-1.5,1.5,10):\n y0 = 2\n i = np.array([0,-0.2])\n n = df(x0, y(x0))\n pn = -np.dot(i, n)/np.dot(n, n) * n\n o = i + 2*pn\n sample = 2\n line = [np.array([x0]*sample), np.linspace(y(x0),2,sample)]\n if x0 < 0:\n x = np.linspace(x0,0,2)\n else:\n x = np.linspace(0,x0, 2)\n z = o[1]/o[0]*(x-x0) + y(x0)\n l, = ax.plot(line[0], line[1], '-')\n ax.quiver(x0, y0, i[0], i[1], angles='xy', scale_units='xy', scale=1)\n ax.quiver(x0, y(x0), o[0], o[1], angles='xy', scale_units='xy', scale=1)\n ax.plot(x, z, '-',c=l.get_color())\n\nx = np.linspace(-2,2,100)\nax.plot(x, y(x), '-k',lw=3)\nax.plot(0, 0.5, 'ok')\n\nax.set_ylim(0,2)\nax.set_xlim(-2,2)\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.15" } }, "nbformat": 4, "nbformat_minor": 0 }