From 352b746cc28185c0ea0b9b6c93b961d4aa88fef8 Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 8 Oct 2018 15:46:03 +0200 Subject: Added a function calculating the forces in between a star and all the stas in the given slice. --- forces/forces.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'forces/forces.go') diff --git a/forces/forces.go b/forces/forces.go index 4539d06..c49692c 100644 --- a/forces/forces.go +++ b/forces/forces.go @@ -7,7 +7,7 @@ import ( // 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 { +func forceActing(s1 structs.Star, s2 structs.Star) structs.Force { // Gravitational constant var G = 6.674 * math.Pow(10, -11) @@ -29,3 +29,27 @@ func ForceActing(s1 structs.Star, s2 structs.Star) structs.Force { return F } + +// forces calculates the forces acting in between a given star and all the other stars in a given array. +func forces(stars_arr []structs.Star, nr int) structs.Force { + + var force structs.Force + + // Iterate over all the stars in the stars_arr + for index := range stars_arr { + + // If the current star is not the star itself + if index != nr { + + // generate a new force and add it to the overall force of the star + fa := forceActing(stars_arr[nr], stars_arr[index]) + stars_arr[nr].F.X += fa.X + stars_arr[nr].F.Y += fa.Y + + force.X += fa.X + force.Y += fa.Y + } + } + + return force +} -- cgit 1.4.1