Closed aryehlev closed 1 year ago
Closing due to age.
Hey, I would be interested in having this feature in the lib and do the implementation. Although, from your short discussion above I could not infer on how much rework of the above code would actually be required. Would appreciate it if you could give me a TLDR @twpayne. Of course only IF this is a feature you want to have in this lib.
This code needs a lot of changes before it can be added to the library, and I would instead recommend implementing your own version in your own project specific to your needs instead.
As well as the numerical accumulation errors in the code here, there are several other problems:
xy
module.Here's roughly what I think the code should look like:
// RegularPolygon returns an n-sided regular polygon centered at center with radius r.
func RegularPolygon(n int, center *geom.Point, r float64) *geom.Polygon {
pointFlatCoords := center.FlatCoords()
stride := center.Stride()
flatCoords := make([]float64, (n+1)*stride)
for i := 0; i < n; i++ {
theta := 2 * math.Pi * float64(i) / float64(n)
flatCoords[i*stride] = pointFlatCoords[0] + r*math.Cos(theta)
flatCoords[i*stride+1] = pointFlatCoords[1] + r*math.Sin(theta)
copy(flatCoords[i*stride+2:(i+1)*stride], pointFlatCoords[2:stride])
}
copy(flatCoords[n*stride:(n+1)*stride], flatCoords[:stride])
return geom.NewPolygonFlat(center.Layout(), flatCoords, []int{(n + 1) * stride})
}
Thanks a lot for your input! I will look into the implementation for our internal project only then.
adding a buffer for 2d points, -> this method creates a polygon by distributing the number of point equaly around a point #