diff options
author | emile <hanemile@protonmail.com> | 2018-10-10 21:38:21 +0200 |
---|---|---|
committer | emile <hanemile@protonmail.com> | 2018-10-10 21:38:21 +0200 |
commit | 8dabefde6078790689e35abdba3952e53042c0cc (patch) | |
tree | 3e494cbb15ebd638c373151e27405fce6ac143fc | |
parent | f97fb6499cb06e1159709b637cebfa489382b266 (diff) |
Define new default stars
-rw-r--r-- | draw/draw.go | 26 | ||||
-rw-r--r-- | main.go | 34 |
2 files changed, 38 insertions, 22 deletions
diff --git a/draw/draw.go b/draw/draw.go index 73cbc5c..e99ef4e 100644 --- a/draw/draw.go +++ b/draw/draw.go @@ -20,7 +20,7 @@ func initializePlot() *gg.Context { dc.Clear() // Invert the Y axis (positive values are on the top and right) - // dc.InvertY() + dc.InvertY() // Set the coordinate midpoint to the middle of the image dc.Translate(imageWidth/2, imageHeight/2) @@ -35,7 +35,7 @@ func saveImage(dc *gg.Context, path string) { // drawStar draws the given stars to the given context func drawStar(dc *gg.Context, star structs.Star) { - dc.DrawPoint(star.C.X/10, star.C.Y/10, 2) + dc.DrawPoint(star.C.X/50, star.C.Y/50, 2) dc.Fill() dc.Stroke() } @@ -47,17 +47,17 @@ func vectorLength(force structs.Force) float64 { func drawForce(dc *gg.Context, star structs.Star) { // controll the length of the vector - var scalingFactor float64 = 32 + var scalingFactor float64 = 15 // Move the "cursor" to the start position of the vector - dc.MoveTo(star.C.X/10, star.C.Y/10) + dc.MoveTo(star.C.X/50, star.C.Y/50) // calculate the length of the vector vecLength := vectorLength(star.F) // Use a sigmoid function to generate useful values for coloring the vectors according to their // strength - var val = 1.0 / (1.0 + math.Exp(-vecLength)) + var val = 1.0 / (1.0 + math.Exp(-vecLength*scalingFactor/2)) // Set the color to a blue / red dc.SetRGB(val, 0, 1-val) @@ -65,10 +65,12 @@ func drawForce(dc *gg.Context, star structs.Star) { // trace the Vector FxUnit := star.F.X / math.Abs(vecLength) FyUnit := star.F.Y / math.Abs(vecLength) - dc.LineTo(star.C.X/10+(FxUnit*scalingFactor), star.C.Y/10+(FyUnit*scalingFactor)) + dc.LineTo(star.C.X/50+(FxUnit*scalingFactor), star.C.Y/50+(FyUnit*scalingFactor)) + // dc.LineTo(star.C.X/100 + (star.F.X * scalingFactor), star.C.Y/100 + (star.F.Y * scalingFactor)) + // // css - dc.SetLineWidth(2) + dc.SetLineWidth(3) // And finally: DRAW (stroke) the vector dc.Stroke() @@ -98,6 +100,16 @@ func Slice(slice []structs.Star, path string) { // draw all the stars in the given slice drawStars(dc, slice) + dc.SetRGB(1, 1, 1) + + // drawing the 4 big stars as bigger white dots + dc.DrawCircle(600, 600, 5) + dc.DrawCircle(-600, 600, 5) + dc.DrawCircle(-600, 0, 5) + dc.DrawCircle(600, -600, 5) + + dc.Fill() + // save the plot to the given path saveImage(dc, path) } diff --git a/main.go b/main.go index d173cba..c83fdc6 100644 --- a/main.go +++ b/main.go @@ -10,27 +10,31 @@ import ( ) func main() { + var threads int = 8 + // the slice starsSlice stores the star structures starsSlice := []structs.Star{ - {structs.Coord{X: 100, Y: 100}, structs.Force{0, 0}, 1000}, - {structs.Coord{X: 200, Y: 300}, structs.Force{0, 0}, 1000}, - {structs.Coord{X: 100, Y: 500}, structs.Force{0, 0}, 1000}, - {structs.Coord{X: -200000.0, Y: 8000.0}, structs.Force{X: 0, Y: 0}, 8000000000}, - {structs.Coord{X: 200000.0, Y: 0.0}, structs.Force{X: 0, Y: 0}, 8000000000}, - {structs.Coord{X: 0.0, Y: 200000}, structs.Force{X: 0, Y: 0}, 8000000000}, - {structs.Coord{X: 20000.0, Y: 80000}, structs.Force{X: 0, Y: 0}, 4000000}, + {structs.Coord{X: 30000, Y: 30000}, structs.Force{0, 0}, 500000000}, + {structs.Coord{X: -30000, Y: 30000}, structs.Force{0, 0}, 500000000}, + {structs.Coord{X: -30000, Y: 0}, structs.Force{0, 0}, 500000000}, + {structs.Coord{X: 30000, Y: -30000}, structs.Force{0, 0}, 500000000}, } + // var starsSlice []structs.Star + + // llog.Good("Opening the csv") + // starsSlice = csv.Import("data/structure03.ita.uni-heidelberg.de_26635.csv", 0, 2000, starsSlice) + starsSlice = csv.Import("data/U_ALL.csv", 0, 50000, starsSlice) + // fmt.Printf("Done\n") - llog.Good("Opening the csv") - starsSlice = csv.Import("data/structure03.ita.uni-heidelberg.de_26635.csv", 0, 2000, starsSlice) - // starsSlice = csv.Import("data/U_ALL.csv", 0, 2000, starsSlice) - fmt.Printf("Done\n") + // llog.Good("Calculate the acting forces") + starsSlice = forces.CalcAllForces(starsSlice, threads) + // starsSlice = forces.CalcAllForcesOld(starsSlice) - llog.Good("Calculate the acting forces") - forces.CalcAllForces(starsSlice) + // for _, e := range starsSlice { + // fmt.Printf("%f %f | %f %f | %f\n", e.C.X, e.C.Y, e.F.X, e.F.Y, e.Mass) + // } - // Filename without suffix and extension - path := "out" + path := "out_2.png" llog.Good(fmt.Sprintf("draw the slice and save it to %s", path)) draw.Slice(starsSlice, path) |