{"id":171,"date":"2021-11-30T01:53:36","date_gmt":"2021-11-30T01:53:36","guid":{"rendered":"https:\/\/tults.com\/?page_id=171"},"modified":"2021-12-02T22:17:16","modified_gmt":"2021-12-02T22:17:16","slug":"physics-maths-and-science","status":"publish","type":"page","link":"https:\/\/tults.com\/index.php\/physics-maths-and-science\/","title":{"rendered":"Physics, Maths and Science"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/tults.com\/index.php\/physics-maths-and-science\/the-pendulum-project\/\">The Pendulum Project<\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Synopsis: The pendulum project was one that I undertook in university to create an inertial double pendulum simulator. The goal was to understand chaos, and to understand how chaos adapts and evolves in a controlled environment. On this page, we talk about point mass pendulum (where the center of gravity is located at the very end of the arm. The report associated with this assignment was based on an inertial double pendulum, where the center of mass is distributed along the entire arm. I have changed it up here for two reasons. Firstly, to make it unique to the assignment, so if some future student goes to copy my work, they will at least have to change some of the maths to get it to work, and secondly, it is far easier to do the maths on a point mass pendulum then it is to to do on an inertial pendulum.<\/p>\n\n\n\n<canvas id=\"Pendulum\" width=\"300\" height=\"300\" style=\"border:1px solid #000000;\"><\/canvas>\n<script>\nvar time = 0;\nvar gravity = 20;\n\nlet theta = 45*Math.PI\/180;\nlet theta_hist = [];\nlet theta_dot = 0;\nlet theta_dot_hist = [];\nlet theta_dub = 0;\nlet theta_dub_hist = [];\nvar mass1 = 10;\nvar length1 = 90;\n\nlet psi = 120*Math.PI\/180;\nlet psi_hist = [];\nlet psi_dot = 0;\nlet psi_dot_hist = [];\nlet psi_dub = 0;\nlet psi_dub_hist = [];\nvar mass2 = 5;\nvar length2 = 55;\nvar dt = 0.05;\n\nfunction updateHist(){\ntheta_hist.unshift(theta);\ntheta_dot_hist.unshift(theta_dot);\ntheta_dub_hist.unshift(theta_dub);\n\npsi_hist.unshift(psi);\npsi_dot_hist.unshift(psi_dot);\npsi_dub_hist.unshift(psi_dub);\n\nif(theta_hist.length > 260)\n{\ntheta_hist.pop();\ntheta_dot_hist.pop();\ntheta_dub_hist.pop();\npsi_hist.pop();\npsi_dub_hist.pop();\npsi_dot_hist.pop();\n}\n\n}\n\nfunction updateValues(){\nvar prev_theta = theta;\nvar prev_psi = psi;\nvar prev_theta_dot = theta_dot;\nvar prev_psi_dot = psi_dot;\n\ntheta_dub = (-1*gravity*(2*mass1+mass2)*Math.sin(theta)-mass2*gravity*Math.sin(theta-2*psi)-2*Math.sin(theta-psi)*mass2*(psi_dot*psi_dot*length2+theta_dot*theta_dot*length1*Math.cos(theta-psi)))\/(length1*(2*mass1 + mass2 -mass2*Math.cos(2*theta-2*psi)));\npsi_dub = (2*Math.sin(theta-psi)*(theta_dub*theta_dub*length1*(mass1+mass2)+gravity*(mass1+mass2)*Math.cos(theta)+psi_dub*psi_dub*length2*mass2*Math.cos(theta-psi)))\/(length2*(2*mass1+mass2-mass2*Math.cos(2*theta-2*psi)));\n\ntheta_dot = theta_dot + theta_dub*dt;\ntheta = theta+theta_dot*dt;\n\npsi_dot = psi_dot + psi_dub*dt;\npsi = psi + psi_dot*dt;\n\nif(theta > 2*Math.PI){\ntheta = theta-2*Math.PI;\n}\nif(psi > 2*Math.PI){\npsi = psi-2*Math.PI;\n}\nif(theta < -2*Math.PI){\ntheta = theta+2*Math.PI;\n}\nif(psi < -2*Math.PI){\npsi = psi+2*Math.PI;\n}\n\nupdateHist();\n\n}\n\nfunction init(){\nwindow.requestAnimationFrame(draw);\n}\n\nfunction draw(){\nvar c = document.getElementById(\"Pendulum\");\nc.parentElement.style.textAlign = \"center\";\nvar ctx = c.getContext(\"2d\");\n\/\/Clear Screen\nctx.clearRect(0, 0, 300, 300);\n\/\/Draw fulcrum\nctx.beginPath();\nctx.arc(150, 50, 5, 0, 2 * Math.PI);\nctx.fillStyle = '#808080';\nctx.fill();\nctx.stroke();\n\nvar x1 = length1*Math.sin(theta) + 150;\nvar y1 = length1*Math.cos(theta) + 50;\n\nvar x2 = length2*Math.sin(psi) + x1;\nvar y2 = length2*Math.cos(psi) + y1;\n\n\/\/Draw tail\nfor(var curVal = 0; curVal < theta_hist.length\/3; curVal++){\n\nctx.globalAlpha = ((theta_hist.length\/3)-curVal)\/(theta_hist.length\/3)\nvar cTheta = theta_hist[curVal];\nvar cPsi = psi_hist[curVal];\nvar cThetax = length1*Math.sin(cTheta) + 150;\nvar cThetay = length1*Math.cos(cTheta) + 50;\nvar cPsix = length2*Math.sin(cPsi) + cThetax;\nvar cPsiy = length2*Math.cos(cPsi) + cThetay;\n\nctx.beginPath();\nctx.arc(cThetax, cThetay, 3, 0, 2*Math.PI);\nctx.fillStyle = '#FFDFBF';\nctx.fill();\n\nctx.beginPath();\nctx.arc(cPsix, cPsiy, 3, 0, 2*Math.PI);\nctx.fillStyle = '#CCB7E5';\nctx.fill();\n\n}\nctx.globalAlpha = 1;\n\n\/\/Draw arms\nctx.beginPath();\nctx.moveTo(150, 50);\nctx.lineTo(x1, y1);\nctx.stroke();\n\nctx.beginPath();\nctx.moveTo(x1, y1);\nctx.lineTo(x2, y2);\nctx.stroke();\n\n\/\/Add Balls\nctx.beginPath();\nctx.arc(x1, y1, 10, 0, 2*Math.PI);\nctx.fillStyle = '#FFDFBF';\nctx.fill();\nctx.stroke();\n\nctx.beginPath();\nctx.arc(x2, y2, 10, 0, 2*Math.PI);\nctx.fillStyle = '#CCB7E5';\nctx.fill();\nctx.stroke();\n\n\/\/update values\nupdateValues();\n\n\/\/Recurse\nwindow.requestAnimationFrame(draw);\n}\n\ninit();\n\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>The Pendulum Project Synopsis: The pendulum project was one that I undertook in university to create an inertial double pendulum simulator. The goal was to understand chaos, and to understand how chaos adapts and evolves in a controlled environment. On this page, we talk about point mass pendulum (where the center of gravity is locatedContinue reading &rarr;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-171","page","type-page","status-publish","hentry","no-thumb"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/pages\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":6,"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/pages\/171\/revisions"}],"predecessor-version":[{"id":580,"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/pages\/171\/revisions\/580"}],"wp:attachment":[{"href":"https:\/\/tults.com\/index.php\/wp-json\/wp\/v2\/media?parent=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}