All Projects → mmcloughlin → spherand

mmcloughlin / spherand

Licence: ISC license
Random points on a sphere in Golang

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

spherand

Random points on a sphere in Golang.

go.dev Reference Build status

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.

Distribution of broken generator

This package correctly picks points on a sphere, providing a uniform distribution visualized below.

Distribution of correct generator

Getting Started

Install with

$ go get -u github.com/mmcloughlin/spherand

Generate a geographical point with

lat, lng := spherand.Geographical()

You can also generate spherical coordinates with Spherical().

If you need to control the random source, use a generator

g := spherand.NewGenerator(rand.New(rand.NewSource(42)))
lat, lng := g.Geographical()

See go.dev for reference.

Diagrams

Generated with globe.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].