diff options
author | hanemile <hanemile@chaosdorf.de> | 2018-09-28 18:09:44 +0200 |
---|---|---|
committer | hanemile <hanemile@chaosdorf.de> | 2018-09-28 18:09:44 +0200 |
commit | 49c3bb3c595d477e345bad0c7d51b32ac72100a3 (patch) | |
tree | 8ac56a6d3a8eb718db904f51d10c7a224fc69829 | |
parent | 9c8dff07f2c059b77a2fe0f2ace0ca009146bad6 (diff) |
function calculating the forces acting inbetween 2 stars
-rw-r--r-- | force.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/force.go b/force.go new file mode 100644 index 0000000..a839459 --- /dev/null +++ b/force.go @@ -0,0 +1,31 @@ +package main + +import ( + "math" +) + +// forces_acting calculates the force inbetween the two given stars s1 and s2 +// The function return the force +func forces_acting(s1 star, s2 star) force { + + // Gravitational constant + var G float64 = 6.674 * math.Pow(10, -11) + + // Distance between the stars + var r21 float64 = 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 := force{s2.c.x - s1.c.x, s2.c.y - s1.c.y} + + // Calculate how strong the star is affected + var F_scalar float64 = G * (s1.mass * s2.mass) / math.Pow(math.Abs(r21), 2) + + // Calculate the overall force by combining the scalar and the vector + var Fx float64 = F_scalar * rhat.x + var Fy float64 = F_scalar * rhat.y + + // Pack the forces in a force structur + F := force{Fx, Fy} + + return F +} |