about summary refs log tree commit diff
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-08 15:43:41 +0200
committeremile <hanemile@protonmail.com>2018-10-08 15:43:41 +0200
commitdb5af94a4ff878e04b277d2a63a91df2304cb9b9 (patch)
treef54d529513eff89dd5ad426764f9a6bcb9c0c1dc
parent9afe2f80f78f16e6c36bd396ce01a031b38151e9 (diff)
added function force_acting that is used to calculate the force acting in between two given stars.
-rw-r--r--forces/forces.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/forces/forces.go b/forces/forces.go
new file mode 100644
index 0000000..4539d06
--- /dev/null
+++ b/forces/forces.go
@@ -0,0 +1,31 @@
+package forces
+
+import (
+	"../structs"
+	"math"
+)
+
+// forces_acting calculates the force inbetween the two given stars s1 and s2
+// The function return the force
+func ForceActing(s1 structs.Star, s2 structs.Star) structs.Force {
+	// Gravitational constant
+	var G = 6.674 * math.Pow(10, -11)
+
+	// Distance between the stars
+	var r21 = math.Sqrt(math.Pow(s2.C.X-s1.C.X, 2) + math.Pow(s2.C.Y-s1.C.Y, 2))
+
+	// Unit vector pointing from s1 to s2
+	rhat := structs.Force{s2.C.X - s1.C.X, s2.C.Y - s1.C.Y}
+
+	// Calculate how strong the star is affected
+	var F_scalar = G * (s1.Mass * s2.Mass) / math.Pow(math.Abs(r21), 2)
+
+	// Calculate the overall force by combining the scalar and the vector
+	var Fx = F_scalar * rhat.X
+	var Fy = F_scalar * rhat.Y
+
+	// Pack the forces in a force structur
+	F := structs.Force{Fx, Fy}
+
+	return F
+}