1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
Helper functions and implementation of a Newton's cradle simulation.
"""
from src.pds_helper import extract_and_convert
from vpython import vector # type: ignore
from support.constants import *
from support.pendulum import make_objects_of_pendulum # type: ignore
from support.types import PendulumEntry
# TODO 1: write the following 5 functions using relevant helper functions from 'pds_helper'.
def uniform_mass_newton_cradle(relative_filepath: str,
mass: float) -> list[PendulumEntry]:
"""
Creates a list of pendula and updates them to have the same mass.
Args:
relative_filepath (str): filepath to access CSV with pendula data
mass (float): mass to be uniformly applied to each pendulum
Returns:
(list[dict]): list of dictionaries, each dictionary corresponding to
a pendulum, with keys as physical attributes
"""
# TODO: create a list that will serve as the required nested list
# as described in the guide using a helper function. Then, for each pendulum,
# set all the mass values in the dictionary to the required argument mass value
...
def uniform_e_newton_cradle(relative_filepath: str,
e_val: float) -> list[PendulumEntry]:
"""
Creates a list of pendula and updates them to have the same coefficient of
restitution.
Args:
relative_filepath (str): filepath to access CSV with pendula data
e_val (float): coefficient of restitution to be uniformly applied to each
pendulum
Returns:
(list[dict]): list of dictionaries, each dictionary corresponding to
a pendulum, with keys as physical attributes
"""
# TODO: similar to the previous function, but you will be updating
# the coefficients of restitution with the relevant value instead
...
def elastic_newton_cradle(relative_filepath: str) -> list[PendulumEntry]:
"""
Creates a list of pendula and updates them to have perfectly elastic
collisions with each other.
Args:
relative_filepath (str): filepath to access CSV with pendula data
Returns:
(list[dict]): list of dictionaries, each dictionary corresponding to
a pendulum, with keys as physical attributes
"""
# TODO: Use a helper function to return a list of pendula with the
# elastic coefficient of restitution value
...
def inelastic_newton_cradle(relative_filepath: str) -> list[PendulumEntry]:
"""
Creates a list of pendula and updates them to have perfectly inelastic
collisions with each other.
Args:
relative_filepath (str): filepath to access CSV with pendula data
Returns:
(list[dict]): list of dictionaries, each dictionary corresponding to
a pendulum, with keys as physical attributes
"""
# TODO: Use a helper function to return a list of pendula with
# the inelastic coefficient of restitution value
...
def make_newton_cradle(relative_filepath: str,
r_param: float,
theta_init: float) -> list[PendulumEntry]:
"""
Uses information from a specific CSV file to make a list of
dictionaries representing each pendula and their physical attributes.
Args:
relative_filepath (str): relative filepath of the CSV file
r_param (float): size parameter used to define pendulum components
theta_init (float): initial angle of the first pendulum (in radians)
Returns:
(list[dict]): list of dictionaries, each dictionary corresponding
to each pendulum, with keys representing physical attributes
"""
# TODO: Use a helper function from 'pds_helper.py' to make a 'pend_list'
# TODO: write a 'for' loop that goes through each pendulum dictionary
# in 'pend_list' and:
# finds the bob color, bob texture, and calculates the axle position
# makes a pendulum with the aforementioned attributes
# assigns that pendulum as the value of the key 'objects'
# initializes the value for the key 'theta' depending on the value of i
# initializes the value for the key 'omega'
...