{"id":1,"date":"2024-04-14T14:42:30","date_gmt":"2024-04-14T14:42:30","guid":{"rendered":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/?p=1"},"modified":"2024-07-17T18:40:51","modified_gmt":"2024-07-17T18:40:51","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/2024\/04\/14\/hello-world\/","title":{"rendered":"Trial"},"content":{"rendered":"\n\n\n\n\n    <!-- Global site tag (gtag.js) - Google Analytics -->\n\n\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag(&#8216;js&#8217;, new Date());\n\n  gtag(&#8216;config&#8217;, &#8216;UA-8175315-16&#8217;);\n\n\n  \n  <title>Rolling<\/title>\n\n\n\n\n<H3> Four views of rolling<\/H3>\n\n    \n\n    <div id=\"buttons\">\n      \n      \n      &lt;input type=&quot;button&quot; id=&quot;stepback&quot; value=&quot;&lt;\n      &gt;&#8221; onclick=&#8221;stepForward()&#8221;&gt;\n      \n    <\/div>\n\n    <div id=\"viewbuttons\">Rolling: \n      \n      \n      \n      \n    <\/div>\n\n\n\n\n  \n\n\/\/ Simulation first posted on 7-20-2018\n\n\n      function setView(newView)\n      {\n             \/\/get the element\n             mode = Number(newView);\n             if (mode == 1) {\n              message1 = &#8220;View 1 &#8211; Rolling is the superposition of pure translation and pure rotation.&#8221;;\n              message2 = &#8220;For a point on the outer edge of the wheel the translational distance&#8221;;\n              message3 = &#8220;traveled equals the distance traveled around the edge in rotation.&#8221;;\n              title = &#8220;Pure translation&#8221;;\n             }\n\n             if (mode == 2) {\n              message1 = &#8220;View 2 &#8211; The net velocity (red) of a particular point is the vector sum of the&#8221;;\n              message2 = &#8220;velocity due to translation (blue) and the velocity due to rotation (green).&#8221;;\n              message3 = &#8220;Note that the net velocity of a point on the bottom of the wheel is zero.&#8221;;\n              title = &#8220;Using superposition to find the net velocity at a point&#8221;;\n             }\n\n             if (mode == 3) {\n              message1 = &#8220;View 3 &#8211; Here you can see how the velocity of a particular point on the edge&#8221;;\n              message2 = &#8220;of a rolling wheel changes as time goes by. The translational velocity is always&#8221;;\n              message3 = &#8220;the same, while the velocity due to rotation steadily changes direction.&#8221;;\n              title = &#8220;See how the net velocity of a point changes as the wheel rolls&#8221;;\n             }\n\n              if (mode == 4) {\n              message1 = &#8220;View 4 &#8211; A point on the outer edge of the wheel traces out an interesting.&#8221;;\n              message2 = &#8220;path &#8211; the shape of this path is called a cycloid. Note that the point is&#8221;;\n              message3 = &#8220;instantaneously at rest when it is in contact with the road.&#8221;\n              title = &#8220;The path followed by a point on the edge of the wheel&#8221;;\n             }\n            \n             reset();\n     }\n\n\n      function play() {\n        window.clearTimeout(timer);\n        runFlag = 1;\n        runMotion();\n\n      }\n\n      function pause() {\n        window.clearTimeout(timer);\n        runFlag = 0;\n\n      }\n\n      function stepForward() {\n        window.clearTimeout(timer);\n        runFlag = 1;\n        drawMotion();\n\n      }\n\n      function stepBack() {\n        window.clearTimeout(timer);\n        index = index-2;\n        if (index &lt; -1) index = -1;\n        time = index\/20;\n        xPos = xBase;\n        runFlag = 1;\n        drawMotion();\n\n      }\n\n\n      function reset() {\n        window.clearTimeout(timer);\n        index = -1;\n        time = 0.0;\n        runFlag = 1;\n\n        runMotion();\n\n      }\n\n\n      var canvas = document.getElementById(&quot;myCanvas&quot;);\n      var context = canvas.getContext(&quot;2d&quot;);\n      var index = -1;\n\n      var xBase = 494;     \/\/ for the graph\n      var xBase2 = 60;   \/\/ for the motion\n      var yBase = 70;     \/\/ for the graph\n      var yBase2 = 230;    \/\/ for the motion\n      var xInit = 37;\n      var message1 = &#039;Choose a view to explore rolling without slipping&#039;;\n      var message2 = &quot; &quot;;\n      var message3 = &quot; &quot;;\n      var title = &quot;Four views of rolling &#8211; use the buttons to choose a view&quot;;\n      var yStart = yBase+120;\n      var plotColor = &#039;#ff00ff&#039;;\n      var scenario = 1;\n      var radius = 5;\n      var time = 0.0;\n      var deltat = 1\/20.0;\n      var timer;\n      var runFlag = 1;\n\n      var mode = 0;\n      var wheelRadius = 80;\n      var nSpokes = 20;\n      var nArray = 600;\n      var cycloid = new Array(nArray);\n      for (var i = 0; i = 4000) runFlag = 0;\n\n  \/\/    console.log(&#8220;In the drawMotion function, with runFlag = &#8221; + runFlag + &#8221; Fx = &#8221; + Fx);\n\n      if (runFlag == 1) {    \/\/      run if runFlag equal 1, not if equal 0\n        \/\/ clear\n        context.clearRect(0, 0, canvas.width, canvas.height);\n\n        index = index + 1;\n\n        \/\/ set background color for the entire thing\n           context.fillStyle = &#8220;#ffd&#8221;;\n           context.fillRect(0, 0, canvas.width, canvas.height);\n\n\n           context.strokeStyle = &#8216;#000&#8217;;\n           context.lineWidth = 1;\n\n\n        \/\/ set line color\n           context.strokeStyle = &#8216;#999&#8217;;\n           context.lineWidth = 2;\n\n           time = index\/50.0;\n\/\/           xPos = vxInit*time;\n\/\/           yPos = vyInit*time &#8211; 0.5*g*time*time;\n\/\/           var vy = vyInit &#8211; g*time;\n \/\/          console.log(time + &#8216; &#8216; + xPos + &#8216; &#8216; + yPos);\n\n\n\n        \/\/ draw the road\n\n        context.beginPath();\n        context.strokeStyle = &#8216;#999&#8217;;\n        context.lineWidth = 20;\n        context.moveTo(50,yBase2);\n        context.lineTo(canvas.width-50,yBase2); \n        context.stroke();       \n\n        if (mode == 0) {    \/\/ draw a stationary wheel\n          context.beginPath();\n          context.strokeStyle = &#8216;black&#8217;;\n          context.lineWidth = 2;\n          context.fillStyle = &#8220;#99f&#8221;\n          context.arc(xBase2+wheelRadius, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n          context.stroke();  \n          context.fill();    \n\n          \/\/ draw spokes\n          for (var i = 0; i &lt; nSpokes; i++) {\n           context.beginPath();\n           context.strokeStyle = &#039;#383&#039;;\n           context.lineWidth = 2;\n           context.moveTo(xBase2+wheelRadius, yBase2-wheelRadius-10);\n           context.lineTo(xBase2+wheelRadius+wheelRadius*Math.cos(2.0*Math.PI*i\/nSpokes), yBase2-wheelRadius-10+wheelRadius*Math.sin(2.0*Math.PI*i\/nSpokes)); \n           context.stroke();       \n\n          }   \n        }\n\n        if (mode == 1) {    \/\/ draw the moving wheel\n          if (index  2.0*Math.PI*wheelRadius) { \n              d = 2.0*Math.PI*wheelRadius; \n              dIndex = Math.trunc(2.0*Math.PI*wheelRadius); \n            }\n            console.log(d);\n            context.beginPath();\n            context.strokeStyle = &#8216;black&#8217;;\n            context.lineWidth = 2;\n            context.fillStyle = &#8220;#99f&#8221;\n            context.arc(xBase2+wheelRadius+d, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n            context.stroke();  \n            context.fill();    \n\n            \/\/ draw spokes\n            for (var i = 0; i &lt; nSpokes; i++) {\n             context.beginPath();\n             context.strokeStyle = &#039;#383&#039;;\n             context.lineWidth = 2;\n             context.moveTo(xBase2+wheelRadius+d, yBase2-wheelRadius-10);\n             context.lineTo(xBase2+wheelRadius+d+wheelRadius*Math.cos((2.0*Math.PI*i\/nSpokes)), yBase2-wheelRadius-10+wheelRadius*Math.sin((2.0*Math.PI*i\/nSpokes))); \n             context.stroke();       \n\n            }  \n            context.beginPath();\n            context.strokeStyle = &quot;red&quot;;\n            context.lineWidth = 3;\n            context.moveTo(xBase2+wheelRadius, yBase2-wheelRadius-10);\n            context.lineTo(xBase2+wheelRadius+d, yBase2-wheelRadius-10);\n            context.stroke();  \n          }\n            else if (index  2.0*Math.PI*wheelRadius) { \n              d = 2.0*Math.PI*wheelRadius; \n              dIndex = Math.trunc(2.0*Math.PI*wheelRadius); \n            }\n            console.log(d);\n            context.beginPath();\n            context.strokeStyle = &#8216;black&#8217;;\n            context.lineWidth = 2;\n            context.fillStyle = &#8220;#99f&#8221;\n            context.arc(xBase2+wheelRadius, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n            context.stroke();  \n            context.fill();    \n\n            \/\/ draw spokes\n            for (var i = 0; i &lt; nSpokes; i++) {\n             context.beginPath();\n             context.strokeStyle = &#039;#383&#039;;\n             context.lineWidth = 2;\n             context.moveTo(xBase2+wheelRadius, yBase2-wheelRadius-10);\n             context.lineTo(xBase2+wheelRadius+wheelRadius*Math.cos((2.0*Math.PI*i\/nSpokes)+d\/wheelRadius), yBase2-wheelRadius-10+wheelRadius*Math.sin((2.0*Math.PI*i\/nSpokes)+d\/wheelRadius)); \n             context.stroke();       \n\n            }  \n            context.beginPath();\n            context.fillStyle = &quot;red&quot;;\n            context.arc(xBase2+wheelRadius-wheelRadius*Math.sin(d\/wheelRadius), yBase2-wheelRadius-10+wheelRadius*Math.cos(d\/wheelRadius), radius, 0, 2 * Math.PI, false); \n            context.fill();  \n           }\n\n            else if (index  2.0*Math.PI*wheelRadius) { \n              d = 2.0*Math.PI*wheelRadius; \n              dIndex = Math.trunc(2.0*Math.PI*wheelRadius); \n            }\n            console.log(d);\n            context.beginPath();\n            context.strokeStyle = &#8216;black&#8217;;\n            context.lineWidth = 2;\n            context.fillStyle = &#8220;#99f&#8221;;\n            context.arc(xBase2+wheelRadius+d, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n            context.stroke();  \n            context.fill();    \n\n            context.beginPath();\n            context.strokeStyle = &#8216;red&#8217;;\n            context.lineWidth = 2;\n            context.arc(xBase2+wheelRadius+d, yBase2-wheelRadius-10, wheelRadius, 0.5*Math.PI+d\/wheelRadius, 2.5 * Math.PI, false);\n            context.stroke();   \n\n            \/\/ draw spokes\n            for (var i = 0; i  1800) { index = -1; }\n        }\n\n        if (mode == 2) {    \/\/ draw a stationary wheel\n          context.beginPath();\n          context.strokeStyle = &#8216;black&#8217;;\n          context.lineWidth = 2;\n          context.fillStyle = &#8220;#99f&#8221;\n          context.arc(xBase2+wheelRadius+Math.PI*wheelRadius, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n          context.stroke();  \n          context.fill();    \n\n          \/\/ draw spokes\n          for (var i = 0; i  2.0*Math.PI*wheelRadius) { \n            d = 2.0*Math.PI*wheelRadius; \n          }\n          console.log(d);\n          context.beginPath();\n          context.strokeStyle = &#8216;black&#8217;;\n          context.lineWidth = 2;\n          context.fillStyle = &#8220;#99f&#8221;\n          context.arc(xBase2+wheelRadius+d, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n          context.stroke();  \n          context.fill();    \n\n          \/\/ draw spokes\n          for (var i = 0; i  600) { index = -1; }\n        }\n\n\n        if (mode == 4) {    \/\/ draw the moving wheel\n          var d = index;\n          var dIndex = index;\n          if (d &gt; 2.0*Math.PI*wheelRadius) { \n            d = 2.0*Math.PI*wheelRadius; \n            dIndex = Math.trunc(2.0*Math.PI*wheelRadius); \n          }\n          console.log(d);\n          context.beginPath();\n          context.strokeStyle = &#8216;black&#8217;;\n          context.lineWidth = 2;\n          context.fillStyle = &#8220;#99f&#8221;\n          context.arc(xBase2+wheelRadius+d, yBase2-wheelRadius-10, wheelRadius, 0, 2 * Math.PI, false);\n          context.stroke();  \n          context.fill();    \n\n          \/\/ draw spokes\n          for (var i = 0; i &lt; nSpokes; i++) {\n           context.beginPath();\n           context.strokeStyle = &#039;#383&#039;;\n           context.lineWidth = 2;\n           context.moveTo(xBase2+wheelRadius+d, yBase2-wheelRadius-10);\n           context.lineTo(xBase2+wheelRadius+d+wheelRadius*Math.cos((2.0*Math.PI*i\/nSpokes)+d\/wheelRadius), yBase2-wheelRadius-10+wheelRadius*Math.sin((2.0*Math.PI*i\/nSpokes)+d\/wheelRadius)); \n           context.stroke();       \n\n          }  \n          context.beginPath();\n          context.fillStyle = &quot;red&quot;;\n          context.arc(xBase2+wheelRadius+d+wheelRadius*Math.sin(d\/wheelRadius), yBase2-wheelRadius-10-wheelRadius*Math.cos(d\/wheelRadius), radius, 0, 2 * Math.PI, false); \n          context.fill();  \n\n          cycloid[dIndex].xValue = xBase2+wheelRadius+d+wheelRadius*Math.sin(d\/wheelRadius);\n          cycloid[dIndex].yValue = yBase2-wheelRadius-10-wheelRadius*Math.cos(d\/wheelRadius);\n\n          for (i=0; i  600) { index = -1; }\n        }\n\n\n\n \/\/     console.log(&#8220;In the drawMotion function, with runFlag = &#8221; + runFlag + &#8221; x2 = &#8221; + x2);\n\n\n\n        context.font = &#8217;16pt Calibri&#8217;;\n        context.fillStyle = &#8216;blue&#8217;;\n\n        context.textAlign = &#8216;left&#8217;;\n        context.fillText(message1, xBase2, 280);\n        context.fillText(message2, xBase2, 310);\n        context.fillText(message3, xBase2, 340);\n\n        context.font = &#8217;16pt Calibri&#8217;;\n        context.fillStyle = &#8216;purple&#8217;;\n\n        context.textAlign = &#8216;center&#8217;;\n        context.fillText(title, canvas.width\/2, 30);\n\n\n      }\n    }\n\n    function runMotion() {\n        drawMotion();\n        if (runFlag == 1) {\n          timer = window.setTimeout(runMotion, 500\/60);\n        }\n      }\n\n\n    function drawArrow(Fx,Fy,Px,Py, arrowColor) {\n           var theta = Math.atan2(Fy,Fx);\n           context.strokeStyle = arrowColor;\n           context.lineWidth = 4;\n           context.beginPath();\n           context.moveTo(Px, Py);\n           context.lineTo(Px+5.0*Fx, Py-5.0*Fy);\n           context.stroke();\n\n           context.lineWidth = 2;\n\n           var Fmag = Math.sqrt(Fx*Fx+Fy*Fy);\n           if (Fmag &gt; 5) Fmag = 5;\n\n           context.fillStyle = arrowColor;\n           context.beginPath();\n           context.moveTo(Px+5.0*Fx-3*Fmag*Math.cos(theta+0.25*(Math.PI\/2)),Py-5.0*Fy+3*Fmag*Math.sin(theta+0.25*(Math.PI\/2)));\n           context.lineTo(Px+5.0*Fx,Py-5.0*Fy);\n           context.lineTo(Px+5.0*Fx-3*Fmag*Math.cos(theta-0.25*(Math.PI\/2)),Py-5.0*Fy+3*Fmag*Math.sin(theta-0.25*(Math.PI\/2)));\n\n           context.stroke();\n           context.fill();\n\n    }\n\n \n\n\n  \n\n\n\n<p>Simulation first posted on 7-20-2018. Written by Andrew Duffy<\/p>\n\n\n\n<p><a href=\"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/\" rel=\"license\"><img decoding=\"async\" style=\"border-width: 0\" src=\"https:\/\/i.creativecommons.org\/l\/by-nc-sa\/4.0\/88x31.png\" alt=\"Creative Commons License\"><\/a><br>This work by Andrew Duffy is licensed under a <a href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/\" rel=\"license\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License<\/a>.<br>This simulation can be found in the collection at <a href=\"http:\/\/physics.bu.edu\/~duffy\/classroom.html\" rel=\"dct:source\">http:\/\/physics.bu.edu\/~duffy\/classroom.html<\/a>. The simulation is shared here as an archive. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(&#8216;js&#8217;, new Date()); gtag(&#8216;config&#8217;, &#8216;UA-8175315-16&#8217;); Rolling Four views of rolling &lt;input type=&quot;button&quot; id=&quot;stepback&quot; value=&quot;&lt; &gt;&#8221; onclick=&#8221;stepForward()&#8221;&gt; Rolling: \/\/ Simulation first posted on 7-20-2018 function setView(newView) { \/\/get the element mode = Number(newView); if (mode == 1) { message1 = &#8220;View 1 &#8211; Rolling is the superposition of pure &hellip; <a href=\"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/2024\/04\/14\/hello-world\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Trial&#8221;<\/span><\/a><\/p>\n","protected":false},"author":86,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"portfolio_post_id":0,"portfolio_citation":"","portfolio_annotation":"","openlab_post_visibility":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":11,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/posts\/1\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openlab.sps.cuny.edu\/joshua-tan-portfolio\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}