diff --git a/projects/projectile/index.html b/projects/projectile/index.html index 63d3938..a27b692 100644 --- a/projects/projectile/index.html +++ b/projects/projectile/index.html @@ -34,17 +34,19 @@ <br /><br /><br /> <h3>Projectile Motion</h3> -<p>To determine to position of the projectile we should compute the position vector \(\vec{r}(t)=x(t)\vec{i}+y(t)\vec{i}\).</p> +<p>To determine to position of the projectile we should compute the position vector \(\vec{r}(t)=x(t)\vec{i}+y(t)\vec{j}\).</p> <h5>\(x(t)\):</h5> <p>We know from Newton second law that \(\sum \vec{F} = m\times \vec{a}_x = m\times a_x(t)\vec{i}\)</p> <p>However, the projectile as a constant speed along \(\vec{i}\). Hence, \(a_x(t) = 0 \).</p> <p>Thus:</p> +\[ v_x(t) = v_{x,0} \] \[ x(t) = \int_{t_0}^t v_{0,x}dt = v_{0,x}t + C = v_{0,x}t + x_0\] <h5>\(y(t)\):</h5> -<p>We know from Newton second law that \(\sum \vec{F} = m\times \vec{a}_y = m\times a_y(t)\vec{i}\)</p> +<p>We know from Newton second law that \(\sum \vec{F} = m\times \vec{a}_y = m\times a_y(t)\vec{j}\)</p> <p>The projectile is under the influence of the gravity that is oriented <em>downward</em>. Hence, \(a_y(t) = -g \).</p> <p>Thus:</p> \[ v_y(t) = \int_{t_0}^t a_{y}(t)dt = -gt+C = -gt + v_{0,y}\] \[ y(t) = \int_{t_0}^t v_y(t)dt = -\frac{1}{2}gt^2 + v_{0,y}t+C=-\frac{1}{2}gt^2 + v_{0,y}t+y_0\] <h5>\(\vec{r}(t)\):</h5> -Finally knowing \(x(t)\) and \(y(t)\) we have \( \vec{r}(t) = \left(\begin{smallmatrix}x(t)\\y(t)\end{smallmatrix}\right) = \left(\begin{smallmatrix}v_{0,x}t + x_0\\-\frac{1}{2}gt^2 + v_{0,y}t+y_0\end{smallmatrix}\right)\) +<p>Finally knowing \(x(t)\) and \(y(t)\) we have \( \vec{r}(t) = \left(\begin{smallmatrix}x(t)\\y(t)\end{smallmatrix}\right) = \left(\begin{smallmatrix}v_{0,x}t + x_0\\-\frac{1}{2}gt^2 + v_{0,y}t+y_0\end{smallmatrix}\right)\)</p> +<p>We can deduce also that \( \vec{v}(t) = \left(\begin{smallmatrix}v_x(t)\\v_y(t)\end{smallmatrix}\right) = \left(\begin{smallmatrix}v_{0,x}\\-gt+v_{0,y}\end{smallmatrix}\right)\)</p> diff --git a/projects/projectile/index.js b/projects/projectile/index.js index 1c03d46..ce6ba44 100644 --- a/projects/projectile/index.js +++ b/projects/projectile/index.js @@ -23,6 +23,13 @@ let projectile= function (p){ vt=p.createElement('span', ''); katex.render("v(t)", vt.elt); + vi=p.createElement('span', ''); + katex.render("\\vec{i}", vi.elt); + + vj=p.createElement('span', ''); + katex.render("\\vec{j}", vj.elt); + + }; // See explanations @@ -35,7 +42,7 @@ let projectile= function (p){ } function v(t) { - return (-g * t + v0) + return -g * t + v0 } let draw_vectors=function(x,y,skiparrow=false){ @@ -44,8 +51,14 @@ let projectile= function (p){ draw_arrow(p,x,y,x+x0,y-v(t),vt,c,skiparrow) p.stroke(200) draw_arrow(p,x0,height-y0,x,y,r,c,skiparrow) - p.stroke(122, 199, 107) + p.stroke(181, 107, 199) draw_arrow(p,x0,height-y0,x0+v0,height-(y0+v0),v0t,c,skiparrow) + + p.stroke(121, 199, 107) + draw_arrow(p,50,50,50,0,vj,c,skiparrow,true) + p.stroke(199,119,107) + draw_arrow(p,50,50,100,50,vi,c,skiparrow) + p.pop() } @@ -71,7 +84,8 @@ let projectile= function (p){ if(t>50 || (height-y0)<y){ end=true } - + + // Update state if(!end){ t+=0.1 dots.push([x,y]) @@ -89,7 +103,6 @@ refresh=function(){ y0=parseFloat(app.y0) v0=parseFloat(app.v0) g=parseFloat(app.g) - console.log(app.x0) p5Load() } diff --git a/public/js/p5_custom.js b/public/js/p5_custom.js index 2cf742b..19a8dd0 100644 --- a/public/js/p5_custom.js +++ b/public/js/p5_custom.js @@ -1,5 +1,5 @@ -draw_arrow=function(p,x1,y1,x2,y2,elt=null,canvas,skiparrow=false){ +draw_arrow=function(p,x1,y1,x2,y2,elt=null,canvas,skiparrow=false,flip=false){ var offset=5 // Reduce the length of the vector to have a better tip location @@ -30,6 +30,12 @@ draw_arrow=function(p,x1,y1,x2,y2,elt=null,canvas,skiparrow=false){ xfactor=1-yfactor justify=15 + if(flip){ + xfactor=-xfactor + yfactor=-yfactor + } + + if(angle>0){ yfactor=-yfactor }