diff options
author | emile <hanemile@protonmail.com> | 2018-10-15 15:32:13 +0200 |
---|---|---|
committer | emile <hanemile@protonmail.com> | 2018-10-15 15:32:13 +0200 |
commit | 088372b31882dd0217d8cc36d7abeac8b6268382 (patch) | |
tree | 72cde48dd5ebdcd1dbe46d1ddec47cda2d2ae592 /draw | |
parent | 04f6bbb6a71b38c2ea40cec68d5de9fe15d430ef (diff) |
refactored the Star type to Star2D
Diffstat (limited to 'draw')
-rw-r--r-- | draw/draw.go | 19 | ||||
-rw-r--r-- | draw/draw3D.go | 58 |
2 files changed, 9 insertions, 68 deletions
diff --git a/draw/draw.go b/draw/draw.go index b66fc7b..1823493 100644 --- a/draw/draw.go +++ b/draw/draw.go @@ -33,8 +33,8 @@ func saveImage(dc *gg.Context, path string) { dc.SavePNG(path) } -// drawStar draws the given stars to the given context -func drawStar(dc *gg.Context, star structs.Star) { +// drawStar2D draws the given stars to the given context +func drawStar2D(dc *gg.Context, star structs.Star2D) { // the radius can be any value inbetween 1e4 and 1e5 // Define the default star radius as 1 and change it according to the stars mass @@ -59,7 +59,7 @@ func vectorLength(force structs.Force) float64 { return math.Sqrt(math.Pow(force.X, 2) + math.Pow(force.Y, 2)) } -func drawForce(dc *gg.Context, star structs.Star) { +func drawForce(dc *gg.Context, star structs.Star2D) { // controll the length of the vector var scalingFactor float64 = 15 @@ -81,8 +81,7 @@ func drawForce(dc *gg.Context, star structs.Star) { FyUnit := star.F.Y / math.Abs(vecLength) 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(3) @@ -90,8 +89,8 @@ func drawForce(dc *gg.Context, star structs.Star) { dc.Stroke() } -// drawStars draws all the stars in the given slice to the given context -func drawStars(dc *gg.Context, slice []structs.Star) { +// drawStar2Ds draws all the stars in the given slice to the given context +func drawStars2D(dc *gg.Context, slice []structs.Star2D) { // draw all the forces in the given slice for _, star := range slice { drawForce(dc, star) @@ -101,18 +100,18 @@ func drawStars(dc *gg.Context, slice []structs.Star) { // draw all the stars in the given slice for _, star := range slice { - drawStar(dc, star) + drawStar2D(dc, star) } } // Slice draws the stars and the forces acting on them and saves the result to the given path -func Slice(slice []structs.Star, path string) { +func Slice(slice []structs.Star2D, path string) { // initialize the plot dc := initializePlot() // draw all the stars in the given slice - drawStars(dc, slice) + drawStars2D(dc, slice) // save the plot to the given path saveImage(dc, path) diff --git a/draw/draw3D.go b/draw/draw3D.go deleted file mode 100644 index 62d0f05..0000000 --- a/draw/draw3D.go +++ /dev/null @@ -1,58 +0,0 @@ -package draw - -import ( - "../llog" - "../structs" - "github.com/fogleman/ln/ln" -) - -func drawStar3D(scene ln.Scene, star structs.Star) ln.Scene { - starSize := 0.1 - oneCorner := ln.Vector{star.C.X - starSize, star.C.Y - starSize, star.C.Z - starSize} - otherCorner := ln.Vector{star.C.X + starSize, star.C.Y + starSize, star.C.Z + starSize} - - scene.Add(ln.NewCube(oneCorner, otherCorner)) - - return scene -} - -func drawStars3D(scene ln.Scene, slice []structs.Star) ln.Scene { - for _, star := range slice { - scene = drawStar3D(scene, star) - } - - return scene -} - -func Slice3D(slice []structs.Star, path string) { - // create a scene and add a single cube - scene := ln.Scene{} - - llog.Good("Drawing the Stars") - scene = drawStars3D(scene, slice) - llog.Good("Done Drawing the Stars") - - // scene.Add(ln.NewCube(ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1})) - - // define camera parameters - eye := ln.Vector{4, 3, 2} // camera position - center := ln.Vector{0, 0, 0} // camera looks at - up := ln.Vector{0, 0, 1} // up direction - - // define rendering parameters - width := 1024.0 // rendered width - height := 1024.0 // rendered height - fovy := 50.0 // vertical field of view, degrees - znear := 0.1 // near z plane - zfar := 10.0 // far z plane - step := 0.01 // how finely to chop the paths for visibility testing - - llog.Good("Configuring path") - // compute 2D paths that depict the 3D scene - paths := scene.Render(eye, center, up, width, height, fovy, znear, zfar, step) - llog.Good("Done") - - // render the paths in an image - llog.Good("Writing to png") - paths.WriteToPNG(path, width, height) -} |