Commit b214980b authored by Jinhuang (Jin) Zhou's avatar Jinhuang (Jin) Zhou
Browse files

go

parent d5b02d42
No related merge requests found
Showing with 13 additions and 31 deletions
+13 -31
"""
CS1 24fa - Assignment 4
Helper functions and implementation of a Newton's cradle simulation.
"""
from vpython import mag, scene, rate
from support.types import PendulumEntry
from src.constants import (
RANGE, SPREADSHEET_ID,
DT, GRAV, R, THETA_INIT,
)
from src.special_cradles import make_newton_cradle
from support.constants import NC_FP, DT, GRAV, R, THETA_INIT
from src.pds_helper import write_to_csv
from src.special_cradles import uniform_mass_newton_cradle, uniform_e_newton_cradle, elastic_newton_cradle, inelastic_newton_cradle, make_newton_cradle
from src.swinging import full_swing_update
scene.title = "Newton's cradle"
# TODO 4: use the physics derivation provided to update velocities post collision
def handle_collision(e: float,
omega1: float,
omega2: float,
m1: float,
m2: float,
r_param: float,
) -> tuple[float, float]:
def handle_collision(e: float, omega1: float, omega2: float, m1: float, m2: float, r_param: float):
"""
In case two bobs collide, handles the physics (momentum conservation).
......@@ -40,30 +26,25 @@ def handle_collision(e: float,
Returns:
(tuple[float, float]): post-collision omegas of 1st, 2nd pendula
"""
# TODO 4: Use the physics derivation provided to update velocities post collision
...
# TODO 5: handle pairwise pendulum motion and collisions
def handle_two_bobs(pend1: PendulumEntry, pend2: PendulumEntry, r_param: float) -> None:
def handle_two_bobs(pend1, pend2, r_param):
"""
Handles the collisions and updates of 2 pendula in the cradle.
Args:
pend1 (PendulumEntry): dictionary representing 1st pendulum,
pend1 (dict): dictionary representing 1st pendulum,
with keys as physical attributes
pend2 (PendulumEntry): dictionary representing 1st pendulum,
pend2 (dict): dictionary representing 1st pendulum,
with keys as physical attributes
r_param (float): size parameter used to define pendulum components
"""
# TODO 5: Handle pairwise pendulum motion and collisions
...
# TODO 6: perform one step of the newton cradle
def newton_cradle_tick(pend_list: list[PendulumEntry],
r_param: float,
dt: float,
g: float,
) -> None:
def newton_cradle_tick(pend_list, r_param, dt, g):
"""
Performs one 'tick' of the entire Newton's cradle (propagates any
motion throughout all the pendula).
......@@ -75,17 +56,18 @@ def newton_cradle_tick(pend_list: list[PendulumEntry],
dt (float): time step of update
g (float): gravitational acceleration
"""
# TODO 6: Perform one step of the newton cradle
...
if __name__ == "__main__":
# TODO 7.1: use a helper function to make pend_list with
# RANGE, SPREADSHEET_ID, R and THETA_INIT
# a filepath called NC_FP, R and THETA_INIT
pend_list = ...
done = False
while not done:
rate(1/DT) # The rate to be included in the animation
rate(1/DT) # The rate to be included in the animation
# TODO 7.2: Use another helper function to perform a timestep of the
# Newton's cradle
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment