about summary refs log tree commit diff
path: root/forces/forces.go
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-08 15:54:09 +0200
committeremile <hanemile@protonmail.com>2018-10-08 15:54:09 +0200
commit59f43b4498fc35a52eee859db07f6b15fc4e2ab3 (patch)
tree79d272b169b7cc7199164b76ae74e165598d19c5 /forces/forces.go
parenta61a2a1c29ddbad8f9b80c979a96e74f63961dd5 (diff)
Not exporting the forces function anymore, because the CalcAllForces function is accessing it.
The CalcAllFucntion calculates all the forces acting in between the stars in the given Slice and returns the slice with the forces stored in the star structs.
Diffstat (limited to 'forces/forces.go')
-rw-r--r--forces/forces.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/forces/forces.go b/forces/forces.go
index 6869630..5d0c414 100644
--- a/forces/forces.go
+++ b/forces/forces.go
@@ -31,7 +31,7 @@ func forceActing(s1 structs.Star, s2 structs.Star) structs.Force {
 }
 
 // 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 {
+func forces(stars_arr []structs.Star, nr int) structs.Force {
 
 	var force structs.Force
 
@@ -53,3 +53,30 @@ func Forces(stars_arr []structs.Star, nr int) structs.Force {
 
 	return force
 }
+
+func CalcAllForces(starSlice []structs.Star) []structs.Star {
+
+	// Define a new slice in which the stars (and the forces acting on them) should be saved
+	var new_slice []structs.Star
+
+	// Iterate over all the stars in the original slice
+	for index := range starSlice {
+
+		// Calculate the force acting inbetween the given star and all other stars
+		// This utilizes go-routines :D
+		var force = forces(starSlice, index)
+
+		// create a new star
+		current_star := structs.Star{
+			structs.Coord{starSlice[index].C.X, starSlice[index].C.Y},
+			structs.Force{force.X, force.Y},
+			starSlice[index].Mass,
+		}
+
+		// append the new star to the new slice
+		new_slice = append(new_slice, current_star)
+
+	}
+
+	return new_slice
+}