https://github.com/mmcloughlin/spherand
Random points on a sphere in Golang
https://github.com/mmcloughlin/spherand
Last synced: 6 months ago
JSON representation
Random points on a sphere in Golang
- Host: GitHub
- URL: https://github.com/mmcloughlin/spherand
- Owner: mmcloughlin
- License: isc
- Created: 2017-07-04T17:32:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-01T19:11:17.000Z (over 5 years ago)
- Last Synced: 2025-04-05T14:47:28.376Z (7 months ago)
- Language: Go
- Homepage: https://godoc.org/github.com/mmcloughlin/spherand
- Size: 9.77 KB
- Stars: 22
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spherand
Random points on a sphere in Golang.
[](https://pkg.go.dev/github.com/mmcloughlin/spherand)
[](https://travis-ci.org/mmcloughlin/spherand)## The Problem
If you generate latitude and longitude uniformly in the ranges `[-90, 90]` and
`[-180, 180]` you will get distributions biased towards the poles.
This package [correctly picks points on a
sphere](http://mathworld.wolfram.com/SpherePointPicking.html), providing a
uniform distribution visualized below.
## Getting Started
Install with
```sh
$ go get -u github.com/mmcloughlin/spherand
```Generate a geographical point with
```go
lat, lng := spherand.Geographical()
```You can also generate spherical coordinates with `Spherical()`.
If you need to control the random source, use a generator
```go
g := spherand.NewGenerator(rand.New(rand.NewSource(42)))
lat, lng := g.Geographical()
```See [go.dev](https://pkg.go.dev/github.com/mmcloughlin/spherand) for reference.
## Diagrams
Generated with [globe](https://github.com/mmcloughlin/globe).