Skip to content
A configurable spherical geodesic grid data model designed for simulations.
Branch: master
Clone or download
thure Merge remote-tracking branch 'origin/master'
# Conflicts:
#	www/sphereworker.js
#	www/src/webpack.js
Latest commit 09ed8c2 Sep 8, 2016

Build Status


A configurable spherical geodesic grid data model designed for simulations and visualization.

The literature extolling spherical geodesic grids as data models for simulations of 2½D spherical phenomena like oceanography and climate is enormous (see references below), but the algorithms for those simulations are often written for research-oriented platforms (i.e. in FORTRAN), making accessibility and portability an issue.

Peels is the first attempt at a JavaScript implementation of the spherical geodesic grid data model for use in browsers or Node. While it was developed as the first component of GEOF, Peels has no gaming-specific functionality and should be useful for other goals as well.


First, install:

npm install --save peels

Next, make a sphere:

var Sphere = require('peels'),
    sphere = new Sphere({divisions: 8});

Peels is still in development; bear in mind the API is likely to change in the near future, especially for methods & properties that begin with an underscore.

Sphere Constructor

The constructor takes an options argument.


When constructing a sphere, you can specify its resolution by passing divisions: [integer] in the constructor's options. The value must be greater than zero, since it is the number of times the edges of the sphere's initial icosahedron will be divided. Though there’s no maximum, bear in mind this value is quadratically related to the model's size/complexity.

In the body of research on spherical geodesic grids, resolution is usually described in terms of ‘level’ of division, where each level yields 2n fields along each edge. divisions in this algorithm is not this metric; each increment of divisions yields n + 1 fields along each edge, i.e. 10n2 + 2 fields across the entire surface of the sphere, allowing much finer control of the model's resolution than most algorithms described in the literature.

A sphere model can be reconstituted from serialized JSON data if that data is provided in this value.

The data must be the product of Sphere.serialize().

Sphere Instance Methods

sphere.iterate(perField, done)

Takes two functions: perField, and done.

For each field in the sphere, perField is called as an async iterator, i.e. with a done function as the only argument to be called when processing the field is finished, and with this set to the current field.

Once perField has been called for all fields in the sphere, done is called with an error argument which is null if no errors occurred.


planet.iterate(function(done){ = {
    temperature: getTemp(this.position),
    pressure: getPressure(this.position)
}, d.resolve);

During iteration, every field’s data property is only affected after the iteration is complete for all fields, so it's safe to assume an adjacent field’s data will be consistent no matter when during the iteration it’s accessed.


Meant to be used in conjunction with ThreeJS.

Returns an object with typed arrays suitable for use in ThreeJS’s BufferGeometry.

Field properties

The data stored to this field. It can be anything.

If this is accessed while iterating over all fields in the sphere, is the field’s data from the beginning of the iteration. Once iterating over all fields is finished, is updated to the new value, if a new value was set.


A reference to the field’s parent sphere model.


Returns a reference to a field adjacent to this one at index i. Twelve fields in the model will be pentagonal and all others are hexagonal, so bear in mind a field will have either 5 or 6 adjacent fields.


Returns an array of the fields adjacent to this one. The length of the array will be either 5 or 6.


An object with spherical latitude/longitude coordinates of the field's barycenter in the style used to navigate Earth in radians. The key λ is latitude (from 0 to 2π), and the key φ is longitude (between π/2 and -π/2, positive is north and negative is south), e.g. a field centered on Seattle would be near:

    "φ": 0.8310430088332776,
    "λ": 4.148333263285652

This property is set during the sphere’s construction and shouldn’t be modified.

Demo image credits

All images used in the demo are public domain.


You can’t perform that action at this time.