Skip to content

Commit 796180a

Browse files
committed
Completed box on an incline
1 parent 72b2ccd commit 796180a

File tree

1 file changed

+115
-24
lines changed

1 file changed

+115
-24
lines changed

Physics/src/Examples/Box_incline.lhs

Lines changed: 115 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,81 @@ Box on an incline
22
=================
33

44
> import Vector.Vector
5+
> import Text.Printf
56

6-
All forces are represented in the form of a vector in this example.
7+
A box with the mass 2kg is resting on an incline. The task is to determinate the resulting force given an angle of the incline.
78

8-
![Incline](incline.png){.float-img-left}
9+
When calculating with forces in this example we will use force vectors. This way we can add and subtract different forces together. We can also scale a force with a scalar.
910

10-
Notation:
11-
$$ fg = gravitational\ accelleration $$
11+
![](incline.png){.float-img-left}
12+
13+
$$ \dot g = gravitational\ acceleration $$
1214

1315
$$ m = mass\ of\ box $$
1416

15-
> fg = V2 0 (-10)
17+
> g :: Vector2 Double
18+
> g = V2 0 (-10)
19+
20+
> m :: Double
1621
> m = 2
1722

18-
A unit vector that we get from a degree $a$.
23+
We scale the gravitational acceleration vector with the mass of the box to get a vector representing the gravitational force.
24+
25+
$$ \dot F_{g} = m \cdot \dot g $$
26+
27+
> fg :: Vector2 Double
28+
> fg = scale m g
29+
30+
> alpha :: Angle
31+
> alpha = pi/4
1932

20-
> unit_normal :: Angle -> Vector2 Double
21-
> unit_normal angle = V2 (cos angle) (sin angle)
33+
A unit vector that we get from a radian $a$.
2234

23-
Force against the incline $F_{\perp}$ from the box (negative in y-axis).
35+
> angle_to_unit_vec :: Angle -> Vector2 Double
36+
> angle_to_unit_vec angle = V2 (cos angle) (sin angle)
37+
38+
Force against the incline from the box we denote as $\dot F_{\perp}$. Since the force is perpendicular against the incline of the surface, we need to create the unit vector for $\dot F_{\perp}$ by adding $-(pi/2)$ radians.
39+
40+
This vector we then scale up, with the magnitude of the gravitational force multiplied by $cos(angle)$, which gives how much the gravitational force that affects $\dot F_{\perp}$.
41+
42+
There are two edge cases. If the incline is flat, it means the incline has the angle 0, and $cos(0) = 1$, which means $\dot F_{g} = \dot F_{\perp}$. If the incline is fully tilted however $\frac{\pi}{2}$, it means that $cos(\frac{\pi}{2}) = 0$ and the gravitational force on the box does not result in any force against the incline.
2443

2544
> f_l_ :: Vector2 Double -> Angle -> Vector2 Double
26-
> f_l_ fa angle = scale ((magnitude fa) * (cos angle)) (unit_normal (angle-(pi/2)))
45+
> f_l_ fa angle = scale ((magnitude fa) * (cos angle)) (angle_to_unit_vec (angle-(pi/2)))
2746

28-
The normal force $F_{n} = - F_{\perp}$ supporting the box from the incline (positive in y-axis):
47+
The normal force $\dot F_{n} = - \dot F_{\perp}$ supporting the box from the incline:
2948

3049
> fn :: Vector2 Double -> Angle -> Vector2 Double
3150
> fn fa angle = negate (f_l_ fa angle)
3251

33-
The resulting force is then the normal force from the incline plus the gravitational force.
34-
$$ F_{r} = F_{n} + F_{g} $$
52+
The $resulting\ force\ \dot F_{r}$ is then the normal force from the incline plus the gravitational force.
53+
$$ \dot F_{r} = \dot F_{n} + \dot F_{g} $$
3554

3655
> fr :: Vector2 Double -> Angle -> Vector2 Double
3756
> fr fa angle = (fn fa angle) + fa
3857

39-
With friction:
58+
We have now determined a way to get the resulting force from a given angle. Below we show how we can use it.
59+
60+
< *Main> fr fg (pi/4)
61+
< (-10.000000000000002, -10.0)
62+
63+
With the use of a rounding printer (defined last in this example) we can round the output.
64+
65+
< *Main> print_vec_2dec $ fr fg (pi/4)
66+
< (-10.00,-10.00)
67+
68+
Here we can see, that $\dot F_{r}$ on the box is pointing down-left in the sense of a coordinate system. To know it's magnitude, we can do:
69+
70+
< magnitude $ fr fg (pi/4)
71+
< 14.142135623730953
72+
73+
Or with rounding:
74+
75+
< print_2dec $ magnitude $ fr fg (pi/4)
76+
< 14.14
77+
78+
Now we try to tackle the problem with friction:
79+
-----------------------------------------------
4080

4181
$$ F_{friction} = \mu * F_{normal} \iff \mu = \frac{F_{friction}}{F_{normal}} $$
4282

@@ -49,27 +89,78 @@ When the object is sliding the maximum friction between the surface and the obje
4989
$$ F_{static\ friction} = \mu_{static} \cdot F_{normal} $$
5090
$$ F_{kinetic\ friction} = \mu_{kinetic} \cdot F_{normal} $$
5191

52-
We have the normal force against the incline and only need example constants.
92+
Given that we know if the box is already moving or not, we can chose the corresponding friction constant and calculate the friction force between the box and the incline. The direction of the friction force will then be in the opposite direction of the resulting force without friction, which we determined in the previous section.
93+
94+
We will use a type definition to clarify parameters.
5395

5496
> type FricConst = Double
55-
> us = 0.5
56-
> uk = 0.4
5797

58-
Från en rörelse eller vekt, fixa komplementet
98+
We will also need to use the unit vector of the resulting force from the previous section.
5999

60100
> unit_vec :: Vector2 Double -> Vector2 Double
61101
> unit_vec v | magnitude v == 0 = (V2 0 0)
62102
> | otherwise = scale (1 / (magnitude v)) v
63103

64-
> motkrafts :: FricConst -> Scalar -> Vector2 Double -> Vector2 Double
65-
> motkrafts u s v = scale (u * s) (negate (unit_vec v))
104+
For a box initally at rest:
105+
---------------------------
66106

67-
> motkraftv :: FricConst -> Vector2 Double -> Vector2 Double -> Vector2 Double
68-
> motkraftv u normal v = scale (u * (magnitude normal)) (negate (unit_vec v))
107+
We let this function compute the friction. If the magnitude of the friction is greater than the magnitude of the resulting force without friction, it means the
108+
box will stand still or that the magnitudes can be treated as equally big.
69109

70-
Now we just need to sum the force vectors into $F_{r}$:
110+
> ff :: Vector2 Double -> Scalar -> Scalar -> FricConst -> Vector2 Double
111+
> ff fr magn_l_ magn_fr u = scale magn_fric (negate (unit_vec fr))
112+
> where
113+
> magn_fric | magn_l_ * u > magn_fr = magn_fr
114+
> | otherwise = magn_l_ * u
115+
116+
Now we just need to add the friction vector to our old $\dot F_{r}$. We call this function fru, from the constant $\mu$:
71117

72118
> fru :: Vector2 Double -> Angle -> FricConst -> Vector2 Double
73-
> fru fa a u = (fr fa a) + (motkraftv u (fn fa a) (fr fa a))
119+
> fru fa a u = (fr fa a) + (ff (fr fa a) magn_l_ magn_fr u)
120+
> where
121+
> magn_l_ = magnitude (f_l_ fa a)
122+
> magn_fr = magnitude (fr fa a)
123+
124+
Testing for $u = 0$. In this case both "fr" and "fru" should give the same resulting vector:
125+
126+
< *Main> print_vec_2dec $ fr fg (pi/3)
127+
< (-8.66,-15.00)
128+
129+
< *Main> print_vec_2dec $ fru fg (pi/3) 0
130+
< (-8.66,-15.00)
131+
132+
They should also give the same if the incline is flat.
133+
134+
< *Main> print_vec_2dec $ fr fg (0)
135+
< (-0.00,0.00)
136+
137+
< *Main> print_vec_2dec $ fru fg (0) 1
138+
< (-0.00,0.00)
139+
140+
Lastly one should see the edge case where the angle is $\frac{\pi}{4}$. The magnitude of the normal and the resulting force from the previous section becomes the same (try and control it!). This also means that if $\mu_{static} = 1$ the magnitude of the friction force becomes $equal$ to the magnitude of the resulting force without friction. The consequence of this will be that the friction force is just enough to prevent the box from sliding. If we increase the angle just a little, the box starts sliding.
141+
142+
< *Main> print_vec_2dec $ fru fg (pi/4) 1
143+
< (-0.00,0.00)
144+
145+
< *Main> print_vec_2dec $ fru fg (0.01 + pi/4) 1
146+
< (-0.20,-0.20)
147+
148+
In this case it may be beneficial to see more decimals, given that it should slide more downwards (down on the y-axis) than to the left (left on the x-axis).
149+
150+
< fru fg (0.01 + pi/4) 1
151+
< (-0.197986733599107, -0.201986600267551)
152+
153+
Friction for a box in motion:
154+
-----------------------------
155+
This one is for you to solve. A box in motion is always affected by the friction (except for one particular edge case).
156+
157+
Pretty printing:
158+
----------------
159+
160+
> print_2dec :: Double -> IO ()
161+
> print_2dec a = putStrLn $ printf "%.2f" a
162+
163+
> print_vec_2dec :: Vector2 Double -> IO ()
164+
> print_vec_2dec (V2 a b) = putStrLn $ "(" ++ (printf "%.2f" a) ++ "," ++ (printf "%.2f" b) ++ ")"
74165

75166

0 commit comments

Comments
 (0)