-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculate_the_resultant_force.js
58 lines (43 loc) · 1.63 KB
/
Calculate_the_resultant_force.js
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
// -------------------------------------------- Description ---------------------------------------
// Given two forces (F1 and F2 ) and the angle F2 makes with F1 find the resultant force R and the angle it makes with F1.
// input
// Three values :
// F1
// F2 making an angle θ with F1
// angle θ
// output
// An array consisting of two values :
// R (the resultant force)
// angle R makes with F1 (φ)
// notes
// Units for each of the following are given as under :
// F1 = Newton
// F2 = Newton
// angle θ = degree
// R = Newton
// φ = degree
// ------------------------------------------------------------------------------------------------
const calculateResultant = (force1, force2, theta) => {
// Convert angle from degrees to radians
var thetaRad = (theta * Math.PI) / 180;
// Calculate the components of force2
var force2x = force2 * Math.cos(thetaRad);
var force2y = force2 * Math.sin(thetaRad);
// Calculate the components of R
var Rx = force1 + force2x;
var Ry = force2y;
// Calculate the magnitude of R
var R = Math.sqrt(Rx * Rx + Ry * Ry);
// Calculate the angle phi (angle between R and F1)
var phiRad = Math.atan2(Ry, Rx);
var phi = (phiRad * 180) / Math.PI;
// Return the resultant force R and angle phi
return [R, phi];
};
// Example usage:
var force1 = 10; // Newton
var force2 = 5; // Newton
var theta = 30; // degrees
var result = calculateResultant(force1, force2, theta);
console.log("Resultant force R: " + result[0] + " Newton"); //Resultant force R: 14.546564555882048 Newton
console.log("Angle phi with F1: " + result[1] + " degrees"); //Angle phi with F1: 9.896090638982898 degrees