diff options
-rw-r--r-- | forces/forces.go | 26 |
1 files changed, 25 insertions, 1 deletions
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 +} |