{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt1" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "67be90b62e46455bb0d9ac794c3d44b4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def Rotx(l,rot):\n", " xr = [0*np.cos(rot)-0*np.sin(rot),(l[0])*np.cos(rot)-0*np.sin(rot),(x)*np.cos(rot)-y*np.sin(rot)]\n", " return xr\n", "\n", "def Roty(l,rot):\n", " yr=[0*np.sin(rot)+0*np.cos(rot),(l[0])*np.sin(rot)+0*np.cos(rot),(x)*np.sin(rot)+y*np.cos(rot)]\n", " return yr\n", "\n", "fig = plt1.figure(figsize=(9,9), constrained_layout=True)\n", "widths = [2,7]\n", "heights = [2,7]\n", "gs=fig.add_gridspec(2,2,width_ratios=widths, height_ratios=heights, wspace=0.05)\n", "\n", "ax1=fig.add_subplot(gs[0:,0:])\n", "ax2=fig.add_subplot(gs[0,0])\n", "\n", "p= np.loadtxt(\"Primetable.txt\", delimiter=\",\", unpack=False)\n", "counter=np.arange(1,len(p)+1)\n", "\n", "ax1.clear()\n", "ax2.clear()\n", "\n", "#Set the number of fibonacci triangles to display\n", "q=56\n", "t=56\n", "\n", "q=56\n", "t=106\n", "\n", "colori=1\n", "\n", "while q <= t:\n", " \n", " #n=q**2\n", " n=q\n", " tempcount=np.arange(1,n)\n", " total=len(tempcount)+1\n", " ax1.clear()\n", " ax2.clear()\n", " \n", " plt1.gca().set_prop_cycle(None)\n", "\n", " rot=0\n", " rot0=np.pi\n", "\n", " x0=[0,0,0]\n", " y0=[0,0,0] \n", " \n", " #Counter for mean graph scaling\n", " m=0\n", " \n", " for i in tempcount:\n", "\n", " #Select 3 following primes, check if hypothenusa is smaller sum sides\n", " l=[p[i-1],p[i],p[i+1]]\n", " if (p[i+1]>(p[i-1]+p[i])):\n", " continue\n", " \n", " l=[p[i-1],p[i-1+26],p[i-1+67]]\n", " if ((p[i-1+67])>(p[i-1]+p[i-1+26])):\n", " continue\n", " \n", " #Determine triangle charesteristics (cosine rule)\n", " alpha=np.arccos((l[1]**2+l[2]**2-l[0]**2)/(2*l[1]*l[2]))\n", " beta=np.arccos((l[0]**2+l[2]**2-l[1]**2)/(2*l[0]*l[2]))\n", " gamma=np.arccos((l[0]**2+l[1]**2-l[2]**2)/(2*l[0]*l[1]))\n", "\n", " #Height Fibonacci Prime Triangle\n", " x=l[0]+l[1]*np.cos(np.pi-gamma)\n", " y=l[2]*np.cos(np.pi/2-beta)\n", "\n", " #Apply Rotation\n", " rot=rot+np.pi-rot0\n", " rot0=gamma\n", " xr=Rotx(l,rot)\n", " yr=Roty(l,rot)\n", "\n", " #Triangle not translation\n", " xr =xr+x0\n", " yr =yr+y0\n", " x0=x*np.cos(rot)-y*np.sin(rot)+x0\n", " y0=x*np.sin(rot)+y*np.cos(rot)+y0\n", " \n", " #Plot triangles and color\n", " color=str(i/(n+55))\n", " ax1.fill(xr,yr,zorder=(-i),c=color)\n", "\n", " r=np.sqrt(((xr[0]+xr[1]+xr[2])/3)**2+((yr[0]+yr[1]+yr[2])/3)**2)\n", " m=m+r\n", " \n", " q=q+1 \n", " \n", " \n", " \n", "#Plot last triangle and scale the plot \n", "ax1.axis([-5*m/total,5*m/total, -5*m/total,5*m/total]) \n", "ax1.plot([xr[0],xr[1],xr[2],xr[0]],[yr[0],yr[1],yr[2],yr[0]],zorder=(0),c='blue',linewidth='0.6') \n", "ax1.axes.get_xaxis().set_visible(False)\n", "ax1.axes.get_yaxis().set_visible(False)\n", "\n", "#Draw reference triangle\n", "c=l[0]+l[1]+l[2]\n", "ax2.fill([0,l[0]/c,x/c],[0,0,y/c],c='0.75')\n", "ax2.plot([0,1/3,0.5/3,0],[0,0,0.5*np.sqrt(3)/3,0],zorder=(5),c='red',linewidth='0.6') \n", "\n", "area=0.5*l[2]*l[0]*np.sin(beta)/c**2\n", "areaequi=0.5*1/3*np.sqrt(3)/6\n", "ratio=area/areaequi\n", "\n", "ax2.axis([-0.05,0.45,-0.05,0.45])\n", "ax2.axis([-0.05,0.45,-0.05,0.45])\n", "ax2.text(0.05,0.95, 'Prime Triangle: [' +str(l[0]) +', '+ str(l[1]) +', '+ str(l[2]) + '] \\nEquilateral Triangle Fit: ' + str(round(ratio,8)) +'.', transform=ax2.transAxes, fontsize=10,\n", " verticalalignment='top')\n", "ax2.axes.get_xaxis().set_visible(False)\n", "ax2.axes.get_yaxis().set_visible(False) \n", "ax2.axis('off')\n", "\n", "plt1.show()\n", "plt1.savefig('Fibonacci Prime Triangle n=' + str(n), dpi=500, bbox_inches='tight')\n", "\n", "\n", "\n", " \n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8.3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "0578bbeed4af451aa662c46ca4d9ca51": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "164e70139bbd47179d4e5fb49d052014": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_d197860480724fa5b4f83e17cb85e630", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "5a1281f5846249828f31da175a7cfaa4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "67be90b62e46455bb0d9ac794c3d44b4": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "MPLCanvasModel", "state": { "_figure_label": "Figure 1", "_height": 900, "_image_mode": "diff", "_message": "x=4570.84 y=-1043.36 ", "_width": 900, "layout": "IPY_MODEL_5a1281f5846249828f31da175a7cfaa4", "toolbar": "IPY_MODEL_6d9c4167cfb04e30ae7906e3f5396ac2", "toolbar_position": "left" } }, "6d9c4167cfb04e30ae7906e3f5396ac2": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.3", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_0578bbeed4af451aa662c46ca4d9ca51", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "d197860480724fa5b4f83e17cb85e630": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "ffb9033ec01f4fcaab4f92d58f42d695": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }