Mercurial > gemma
diff pkg/octree/vertex.go @ 3650:01ce3ba9b0d0 single-beam
Fixed generating of random points.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 13 Jun 2019 13:14:40 +0200 |
parents | 810b28f59b8b |
children | a6c671abbc35 |
line wrap: on
line diff
--- a/pkg/octree/vertex.go Wed Jun 12 17:30:20 2019 +0200 +++ b/pkg/octree/vertex.go Thu Jun 13 13:14:40 2019 +0200 @@ -210,6 +210,11 @@ return math.Hypot(v.X-w.X, v.Y-w.Y) } +func (v Vertex) Distance(w Vertex) float64 { + v = v.Sub(w) + return math.Sqrt(v.Dot(v)) +} + // Minimize adjust this vertex v to hold the minimum // values component-wise of v and w. func (v *Vertex) Minimize(w Vertex) { @@ -441,6 +446,34 @@ } } +func (ls LineStringZ) Buffer(radius float64) { + if len(ls) == 0 { + return + } + var cx, cy, cz float64 + for i := range ls { + cx += ls[i].X + cy += ls[i].Y + cz += ls[i].Z + } + + s := 1.0 / float64(len(ls)) + + cx *= s + cy *= s + cz *= s + c := Vertex{X: cx, Y: cy, Z: cz} + for i := range ls { + n := c.Sub(ls[i]).Normalize() + l := ls[i].Distance(c) + // l = 1 + // l + r = s + // (l+r)/l = s + s := (l + radius) / l + ls[i] = ls[i].Add(n.Scale(s)) + } +} + func (ls LineStringZ) order(position func(Vertex) float64) { type posVertex struct { pos float64