# NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

## Information about this web site => Question related to Physics or physics related simulation => Topic started by: Mardoxx on April 18, 2010, 04:47:57 am

 Title: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 18, 2010, 04:47:57 am Hi!I'm REALLY hoping you can help me here!I've been asked to produce the following using vPython, if you could help me setup a model, or even create one in java, I can then quite easily convert it to python.I just need to have the basic physics explained to me... I've attempted it myself but I really can't get my head around it!!!!here goes:QuoteA mass of 2 kg is dropped vertically into a frictionless slide located in the x-y plane. The mass enters with zero velocity at (-5,5) and exits travelling horizontally at (0,0).Assuming the slide to be perfectly circular in shape construct a model of the forces acting on the mass and hence simulate its motion. So, it's a quarter-circle starting at (-5,5), ending at (0,0) with centre (0,5) i.e.(http://i43.tinypic.com/kby4b8.png)Initial velocity is (0,0), initial position is (-5,5), initial acceleration is (0,-g) ( where g is 9.81ms^2)I have attempted to draw force lines and things but ... agggh!! Variable acceleration!!!!!I can't handle it, Please can you help me !! :)Thanks,Mardoxx Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 18, 2010, 08:46:32 am The above is the same problem as a real pendulum.Do you know how to solve the pendulum problem?Using $\theta$ as the main variable,model:  $\frac{d^2\theta}{dt^2}=-\frac{g}{R}\sin\theta$ Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 18, 2010, 06:58:16 pm I thought that for a pendulum the angle had to be small, this is pi/2 though :(This is my attempt at it : http://mathbin.net/45802 - I don't think it's rightHow do you solve it, I'm stuck because $\frac{d^2\theta}{dt^2}$ is not a function of time, it's a function of $\theta$ :( Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 18, 2010, 09:49:21 pm If you are going to use a program to solve it. What you need is not an analytical solution.You should solve it numerically.$\frac{d^2\theta}{dt^2}=-\frac{g}{R}\sin\theta$can be break into two first order differential equation$\frac{d\theta}{dt}=\omega$ and $\frac{d\omega}{dt}=-\frac{g}{R}\sin\theta$You should know the initial condition $\theta(0)$ and $\omega(0)$With Euler's method: $\theta(dt)=\theta(0)+\omega *dt$ $\omega(dt)=-\frac{g}{R}\sin\theta(0)*dt$It means that $\theta(t+dt)$ and $\omega(t+dt)$ can be calculated from $\theta(t)$ and $\omega(t)$The time step need to be small enough to avoid accumuation of numerical error.There are better numerical method to solve it. e.g. Runge-Kutta 4th order.I think you are learning it right now? Right? Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 18, 2010, 10:36:22 pm Thanks,Nope, I haven't learned any of this....IDK why we were given it as a question this early on!! :PI don't get how this works for a pendulum (or my ball) starting at 0 radians, becuase then $\theta(t+dt)=0$ which is wrong :(Do you use IRC at all, because live chat would be loads quicker :P Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 19, 2010, 05:07:53 am I've done it!!!!but using python + vpythonAll i need to do now is how to display the forces.I think i need them in vector form with magnitude and direction.Would you be able to help please?Code:import visual as vfrom math import sin, cos, pi, sqrtfrom sys import *''' Curve radius extended by radius of curve-frame + radius of ball so that the ball slides along the curve, not through it :P '''r = 5 + 0.1t = v.arange(pi, 3*pi/2, 0.0001)c = v.curve(x = r * v.cos(t), y = r * v.sin(t) + 5, z = 0, radius=0)# ball starts at -5,5mass = v.sphere(pos=(-5,5), radius=0.1, color=v.color.red)def rk4(t0, h, s0, f): # From http://doswa.com/blog/2009/04/21/improved-rk4-implementation/ '''RK4 implementation. t = current value of the independent variable h = amount to increase the independent variable (step size) s0 = initial state as a list. ex.: [initial_position, initial_velocity] f = function(state, t) to integrate''' r = range(len(s0)) s1 = s0 + [f(t0, s0)] s2 = [s0[i] + 0.5*s1[i+1]*h for i in r] s2 += [f(t0+0.5*h, s2)] s3 = [s0[i] + 0.5*s2[i+1]*h for i in r] s3 += [f(t0+0.5*h, s3)] s4 = [s0[i] + s3[i+1]*h for i in r] s4 += [f(t0+h, s4)] return t+h, [s0[i] + (s1[i+1] + 2*(s2[i+1]+s3[i+1]) + s4[i+1])*h/6.0 for i in r] def pendulum_angular_accel(t,s): ''' theta'  = omega     omega' = theta'' = -g/R sin(theta) = angular acceleration ''' theta = s ''' angle at time t = s    omega at time t = s    alpha at time t = (-g/R)*sin(s) ''' g = 9.80665 R = 5 return (-g/R)*sin(theta)g = 9.80665 # accel due to gravityt = 0 # initial t is 0h = 0.0001 # dts = [3*pi/2, 0] # initial position and initial angular velocitywhile (s <= 2*pi): # phi <= pi/2 v.rate(2500) alpha = (-g/5)*sin(s) phi = s-3*pi/2 x =  -5*cos(phi) y = 5-5*sin(phi) mass.pos = v.vector(x,y) t, s = rk4(t, h, s, pendulum_angular_accel)print "Final velocity:     r*omega = v = ", str(5*s), "m/s"print "Final velocity: sqrt(2*g*h) = v = ", str(sqrt(10*g)), "m/s"print "Total travel time:            t = ", str(t), "s" Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 19, 2010, 09:18:02 am Quote from: Mardoxx on April 18, 2010, 10:36:22 pmI don't get how this works for a pendulum (or my ball) starting at 0 radians, becuase then $\theta(t+dt)=0$ which is wrong :(There is nothing wrong with it. If you set $\theta(0)=0$ and you find $\theta(t+dt)=0$ it means you also set $\omega(0)=0$How can a pendulum move if it at equilibrium position without any initial velocity or external force.If $\theta(0)=0$, you will need to set $\omega(0)\ne 0$, otherwise the pendulum will not move at all. $\frac{d^2\theta}{dt^2}=-\frac{g}{R}\sin\theta$ is the angular acceleration at any point.So you should be able to find linear acceleration $a= R\alpha = R \frac{d^2\theta}{dt^2}$ which is the magnitude of the force. And it's direction is in the tangential direction.You might be able to  find out each component (x,y component) of the tangential component  if you try to draw it's component in a paper.I will try to help if you still can not figure it out by yourself. But I will let you try it first.  Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 19, 2010, 05:59:25 pm thanks :)I got thisradial.axis        = -v.vector(5*cos(phi)*s**2, 5*sin(phi)*s**2)       # -m*r*omega^2transverse.axis =  v.vector(5*sin(phi)*alpha, -5*cos(phi)*alpha)/(2.1*g)  # m*R*alphaI'm not sure this is correct though, what's happened to m*g being subtracted?Is that needed?------I know where i was going wrong with the angles now, I forgot that they're measured from the line x=0 to the pendulum bob's position :P Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 19, 2010, 06:24:59 pm At any moment, the tension force $T$ minus $m\vec{g}$ and Centripetal force force $-mr\omega^2\hat{r}$ is the tangential component of force which drive the pendulum $-mg \sin\theta \hat{\theta}$i.e. $\vec{T}-m\vec{g}+mr\omega^2\hat{r}= -mg \sin\theta \,\hat{\theta}$So you can find $\vec{T}= m\vec{g}-mg \sin\theta\, \hat{\theta}-mr\omega^2\hat{r}$or Radial component: $T=- (mr\omega^2+mg\cos\theta) \hat{r}$Tangential Component: $- mg\sin\theta\, \hat{\theta}$ Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 19, 2010, 08:34:41 pm Shouldn't T=0 since the ball isn't being held by a string?Also what's $\hat{r}$? the unit vector in the direction of the point (0,5)? If so, what would that be? Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 20, 2010, 12:36:04 am Sorry! T is for a pendulum. It should be changed to Normal force $\vec{N}$ for your case.But the equation is the same.For you case: $\hat{r}$ is the unit vector from (5,0) to (x,y) of the ball.i.e. unit vector of (x-5,y) or $( \frac{x-5}{\sqrt{(x-t)^2+y^2}}, \frac{y}{\sqrt{(x-t)^2+y^2}})$ Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 20, 2010, 11:29:50 pm Thanks!I'm not too good with vectors :/What would $\hat{\theta}$ be?Would it be the negative value of $\hat{r}$? Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 20, 2010, 11:38:00 pm $\hat{r}$ and $\hat{\theta}$ are perpendicular to each other.One is normal component, another one is tangential component. Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 21, 2010, 01:53:05 am The final $\omega$ I get is 1.98057060132 (i.e. when $\theta = 0$ )so when we're bottom of the pendulum (or the end of the slope)$\vec{N} = - (mr\omega^2+mg\cos\theta) \hat{r}$since $\theta = 0$ shouldn't$mr\omega^2 = mg$?because mine comes out as$mr\omega^2 = 2mg$? Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Mardoxx on April 21, 2010, 03:39:09 am I think i've got it now:Code:import visual as vfrom math import sin, cos, pi, sqrtm = 2.1 # mass of mass in kgr = 5    # radius of circle in mg = 9.80665 # accel due to gravityt = 0 # initial t is 0dt = 0.0001 # time incrementv_max = sqrt(2*r*g) # max velocity rate = 2500scene = v.display(title='Mass Sliding Down a Smooth Curve',   width=600,   height=600,   center=(-2.5,2.5),   uniform=1,   range=4,   userzoom = 0,   userspin = 0)''' Curve radius extended by radius of curve-frame + radius of ball so that the ball slides along the curve, not through it :P '''mass_radius = 0.1curve_radius = 5 + mass_radiusvect_length = 1 # so mg is 1 vect_lengthlegend_mass = v.sphere(pos=(-1,4.5), radius=mass_radius, color=v.color.red)mass_label = v.label(pos=legend_mass.pos,    text='Mass, 2.1kg', xoffset=-20,    yoffset=12, space=0.1,    height=10, border=6,    font='sans')legend_mg = v.arrow(pos=legend_mass.pos, axis=(0,-1), shaftwidth=0.05, color=v.color.green)mg_label = v.label(pos=legend_mass.pos+(legend_mg.axis/2),    text='Force due to gravity', xoffset=-20,    yoffset=12, space=0.1,    height=10, border=6,    font='sans')legend_radial = v.arrow(pos=legend_mass.pos, axis=(0.5,0.5), shaftwidth=0.05, color=v.color.yellow)radial_label = v.label(pos=legend_mass.pos+(legend_radial.axis/2),    text='Radial Force', xoffset=-36,    yoffset=32, space=0.1,    height=10, border=6,    font='sans')legend_transverse = v.arrow(pos=legend_mass.pos, axis=(0.25,-0.25), shaftwidth=0.05, color=v.color.blue)transverse_label = v.label(pos=legend_mass.pos+(legend_transverse.axis/2),    text='Transverse Force', xoffset=30,    yoffset=12, space=0.1,    height=10, border=6,    font='sans')xystart_label = v.label(pos=(-5.1,5),    text='(-5,5)', xoffset=-20,    yoffset=0, space=0.1,    height=10, border=6,    font='sans')xyend_label = v.label(pos=(0,-0.1),    text='(0,0)', xoffset=-0.1,    yoffset=-20, space=0.1,    height=10, border=6,    font='sans')start_label = v.text(pos=(-2.5,2.5),    text='Click to\nStart', align='center', font='sans', depth = 0.1, width = 1)# makes a quarter circle radius 5 from (-5,5) to (0,0) centre (0,5)curve_angle = v.arange(pi,    3*pi/2,    0.0001)curve = v.curve(x = curve_radius * v.cos(curve_angle), y = curve_radius * v.sin(curve_angle) + 5, z = 0, radius=0)curve2 = v.curve(x = v.arange(0,10,1), y = -0.1, z = 0, radius=0)# ball starts at -5,5mass = v.sphere(pos=(-5,5), radius=mass_radius, color=v.color.red)mg = v.arrow(pos=mass.pos, axis=-vect_length*(v.vector(0,1)), shaftwidth=0.05, color=v.color.green)radial = v.arrow(pos=mass.pos, axis=(0,0), shaftwidth=0.05, color=v.color.yellow)transverse = v.arrow(pos=mass.pos, axis=(0,0), shaftwidth=0.05, color=v.color.blue)def rk4(t0, h, s0, f): # From http://doswa.com/blog/2009/04/21/improved-rk4-implementation/ '''RK4 implementation. t = current value of the independent variable h = amount to increase the independent variable (step size) s0 = initial state as a list. ex.: [initial_position, initial_velocity] f = function(state, t) to integrate''' r = range(len(s0)) s1 = s0 + [f(t0, s0)] s2 = [s0[i] + 0.5*s1[i+1]*h for i in r] s2 += [f(t0+0.5*h, s2)] s3 = [s0[i] + 0.5*s2[i+1]*h for i in r] s3 += [f(t0+0.5*h, s3)] s4 = [s0[i] + s3[i+1]*h for i in r] s4 += [f(t0+h, s4)] return t+h, [s0[i] + (s1[i+1] + 2*(s2[i+1]+s3[i+1]) + s4[i+1])*h/6.0 for i in r] def pendulum_angular_accel(t,s): ''' theta'  = omega     omega'  = theta'' = -g/R sin(theta) = alpha ''' theta = s ''' angle at time t = s    omega at time t = s    alpha at time t = (-g/R)*sin(s) ''' g = 9.80665 R = 5 return (-g/R)*sin(theta)x = -5y = 5s = [-pi/2, 0]  # initial angle measured from the line x=0 # and initial angular velocity ''' #f = open('csv.csv', 'w')#f.write("t,phi,omega,alpha,x,y\n")# While while True: if scene.mouse.clicked: start_label.visible=False while (x <= 0): # phi <= pi/2 v.rate(rate) # alpha + (-g/5)*sin(s) # uncomment if you want to calculate angular accelerarion phi = s+pi/2 # angle from the line y=5 to the mass x =  -5*cos(phi) y = 5-5*sin(phi) # move mass and force arrows to new location mass.pos = v.vector(x,y) radial.pos = mass.pos transverse.pos = mass.pos mg.pos = mass.pos # calculate forces rhat = v.norm(v.vector(-x/25, (5-y)/25)) radial_max = ((m*v_max**2)/r)+(m*g) # max radial force radial.axis = (vect_length/radial_max)*(((m*r*s**2)+(m*g*cos(s)))*rhat) thetahat = v.norm(v.vector(radial.axis.y,-radial.axis.x)) # theta hat is at right angles to radial transverse.axis = (vect_length/(2*m*g))*(-(m*g*sin(s))*thetahat) t, s = rk4(t, dt, s, pendulum_angular_accel) curve_t = t while (mass.pos.x <= 1.6): v.rate(rate) #speed = distance/time #distance = speed * time mass.pos = mass.pos + v.vector(5*s*dt,0) radial.pos = mass.pos transverse.pos = mass.pos mg.pos = mass.pos t += dt breakprint "Final velocity from model:"print "        r*omega = v = ", str(5*s), "m/s"print "Final velocity using conservation of energy:"print "    sqrt(2*g*h) = v = ", str(v_max),  "m/s"print "Total time to travel down the curve:"print                   "t = ", str(curve_t), "s"compile it using python (32bit) and vpython :D Title: Re: Ball sliding down a smooth quarter-pipe! Post by: Fu-Kwun Hwang on April 21, 2010, 10:04:12 am What is important is not the program skill, but what is the physics involved and mathematic skill.Good to know that you have solved it by yourself.