1---
2version: 0.1.0
3precision: 3
4form_title: Combining Forces
5form_description: Two ropes pull a crate at different angles — what's the net pull, and which way? Enter each force's magnitude and angle above horizontal.
6form_inputs: Force 1 magnitude (N)|f1_mag, Force 1 angle (°)|f1_deg, Force 2 magnitude (N)|f2_mag, Force 2 angle (°)|f2_deg
7form_outputs: Net force x (N)|net_x, Net force y (N)|net_y, Net force magnitude (N)|net_mag, Net force direction (°)|net_dir
8---
9# draftply Pro — Vector2D Class: Combining Forces
10# "Two ropes pull a crate at different angles — what's the net pull, and
11# which way?" A small class keeps a vector's x/y and its operations together.
12# This notebook also has a FORM (Pro): tap the form icon for an input mask.
13
14class Vector2D(x, y):
15 def magnitude():
16 return sqrt(self.x^2 + self.y^2)
17 def angle_deg():
18 return atan2(self.y, self.x) * 180 / pi
19 def add(other):
20 return Vector2D(self.x + other.x, self.y + other.y)
21
22# ── The two forces (N, ° above horizontal) ──────
23f1_mag = 120
24f1_deg = 30
25f2_mag = 90
26f2_deg = 110
27
28f1 = Vector2D(f1_mag * cos(f1_deg * pi / 180), f1_mag * sin(f1_deg * pi / 180))
29f2 = Vector2D(f2_mag * cos(f2_deg * pi / 180), f2_mag * sin(f2_deg * pi / 180))
30
31net = f1.add(f2)
32
33net_x = net.x
34net_y = net.y
35net_mag = net.magnitude()
36net_dir = net.angle_deg()
37
38"Net force x (N)": net_x
39"Net force y (N)": net_y
40"Net force magnitude (N)": net_mag
41"Net force direction (°)": net_dir
42