NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 21, 2017, 06:24:18 am

Brevity is the Soul of wit. ..."Shakespeare (154-1616, English dramatist and poet) "

 Pages: [1]   Go Down
 Author Topic: Ball sliding down a smooth quarter-pipe!  (Read 12012 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message on: April 18, 2010, 04:47:57 am » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

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:
Quote
A 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.

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
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #1 on: April 18, 2010, 08:46:32 am » posted from:Taipei,T\'ai-pei,Taiwan

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$
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #2 on: April 18, 2010, 06:58:16 pm » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

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 right

How 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$
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #3 on: April 18, 2010, 09:49:21 pm » posted from:Taipei,T\'ai-pei,Taiwan

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?
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #4 on: April 18, 2010, 10:36:22 pm » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

Thanks,
Nope, I haven't learned any of this....

IDK why we were given it as a question this early on!!

I 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
 « Last Edit: April 18, 2010, 10:41:02 pm by Mardoxx » Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #5 on: April 19, 2010, 05:07:53 am » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

I've done it!!!!
but using python + vpython

All 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 v
from math import sin, cos, pi, sqrt
from sys import *

so that the ball slides along the curve, not through it :P '''
r = 5 + 0.1
t = 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,5

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[0]
''' angle at time t = s[0]
omega at time t = s[1]
alpha at time t = (-g/R)*sin(s[0]) '''
g = 9.80665
R = 5
return (-g/R)*sin(theta)

g = 9.80665 # accel due to gravity
t = 0 # initial t is 0
h = 0.0001 # dt
s = [3*pi/2, 0] # initial position and initial angular velocity

while (s[0] <= 2*pi): # phi <= pi/2
v.rate(2500)
alpha = (-g/5)*sin(s[0])
phi = s[0]-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[1]), "m/s"
print "Final velocity: sqrt(2*g*h) = v = ", str(sqrt(10*g)), "m/s"
print "Total travel time:  t = ", str(t), "s"
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #6 on: April 19, 2010, 09:18:02 am » posted from:Taipei,T\'ai-pei,Taiwan

I 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.

 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #7 on: April 19, 2010, 05:59:25 pm » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

thanks

I got this

radial.axis  = -v.vector(5*cos(phi)*s[1]**2, 5*sin(phi)*s[1]**2)  # -m*r*omega^2
transverse.axis =  v.vector(5*sin(phi)*alpha, -5*cos(phi)*alpha)/(2.1*g)  # m*R*alpha

I'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
 « Last Edit: April 19, 2010, 06:18:37 pm by Mardoxx » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #8 on: April 19, 2010, 06:24:59 pm » posted from:Taipei,T\'ai-pei,Taiwan

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}$
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #9 on: April 19, 2010, 08:34:41 pm » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

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?
 « Last Edit: April 19, 2010, 09:08:22 pm by Mardoxx » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #10 on: April 20, 2010, 12:36:04 am » posted from:Taipei,T\'ai-pei,Taiwan

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}})$
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #11 on: April 20, 2010, 11:29:50 pm » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

Thanks!
I'm not too good with vectors :/
What would $\hat{\theta}$ be?
Would it be the negative value of $\hat{r}$?
 « Last Edit: April 20, 2010, 11:32:55 pm by Mardoxx » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #12 on: April 20, 2010, 11:38:00 pm » posted from:Taipei,T\'ai-pei,Taiwan

$\hat{r}$ and $\hat{\theta}$ are perpendicular to each other.
One is normal component, another one is tangential component.
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #13 on: April 21, 2010, 01:53:05 am » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

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$?
 Logged
Mardoxx
Newbie

Offline

Posts: 13

 « Embed this message Reply #14 on: April 21, 2010, 03:39:09 am » posted from:Kingston Upon Hull,Kingston upon Hull, City of,United Kingdom

I think i've got it now:

Code:
import visual as v
from math import sin, cos, pi, sqrt

m = 2.1 # mass of mass in kg
r = 5  # radius of circle in m
g = 9.80665 # accel due to gravity
t = 0 # initial t is 0
dt = 0.0001 # time increment
v_max = sqrt(2*r*g) # max velocity
rate = 2500

scene = 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)
so that the ball slides along the curve, not through it :P '''
vect_length = 1 # so mg is 1 vect_length

legend_mass = v.sphere(pos=(-1,4.5),
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')
axis=(0.5,0.5),
shaftwidth=0.05,
color=v.color.yellow)
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,
curve2 = v.curve(x = v.arange(0,10,1),
y = -0.1,
z = 0,

# ball starts at -5,5
mass = v.sphere(pos=(-5,5),
color=v.color.red)
mg = v.arrow(pos=mass.pos,
axis=-vect_length*(v.vector(0,1)),
shaftwidth=0.05,
color=v.color.green)
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[0]
''' angle at time t = s[0]
omega at time t = s[1]
alpha at time t = (-g/R)*sin(s[0]) '''
g = 9.80665
R = 5
return (-g/R)*sin(theta)

x = -5
y = 5
s = [-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[0]) # uncomment if you want to calculate angular accelerarion
phi = s[0]+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)
transverse.pos = mass.pos
mg.pos = mass.pos

# calculate forces
rhat = v.norm(v.vector(-x/25, (5-y)/25))
transverse.axis = (vect_length/(2*m*g))*(-(m*g*sin(s[0]))*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[1]*dt,0)
transverse.pos = mass.pos
mg.pos = mass.pos
t += dt
break
print "Final velocity from model:"
print "  r*omega = v = ", str(5*s[1]), "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
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #15 on: April 21, 2010, 10:04:12 am » posted from:Taipei,T'ai-pei,Taiwan

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.
 Logged
 Pages: [1]   Go Up
Brevity is the Soul of wit. ..."Shakespeare (154-1616, English dramatist and poet) "