Grid Sphere

Produces a nearly even grid over the surface of a sphere.
2.8K Downloads
Updated 13 Mar 2015

View License

The grid may have a total of exactly 12, 42, 162, 642, ... points. Mathematically speaking, the grid may have either 12 or 2 + ( 10 * (4 ^ k) ) points, where k is a positive integer. The user may request any number of points, and the closest attainable value will be produced. All code is compatible with GNU Octave. The algorithm was developed by Nick A. Teanby of Oxford University. Refer to his website for the publication describing the approach and more elaborate geodesic grid software written in IDL: http://www.atm.ox.ac.uk/user/teanby/software.html#icos. Use the FindNearestNeighbors function, available on the MATLAB file exchange at http://www.mathworks.com/matlabcentral/fileexchange/28844-find-nearest-neighbors-on-sphere, to find the grid points closest to arbitrary query points.
GridSphere and FindNearestNeighbors share some functions in common. Each package contains a copy of these functions so that both can stand alone. To eliminate duplicates, simply move all the files into a single folder and replace the shared files when prompted.
Sample usage:
[latGridInDegrees, longGridInDegrees] = GridSphere(12)
latGridInDegrees =
-58.28253
-58.28253
-31.71747
-31.71747
0.00000
0.00000
0.00000
0.00000
31.71747
31.71747
58.28253
58.28253
longGridInDegrees =

0.00000
180.00000
-90.00000
90.00000
-148.28253
-31.71747
31.71747
148.28253
-90.00000
90.00000
0.00000
180.00000

Cite As

Kurt von Laven (2024). Grid Sphere (https://www.mathworks.com/matlabcentral/fileexchange/28842-grid-sphere), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.15

Added a link to another FX submission that this submission uses code from.

1.14.0.0

Moved some words in comments onto previous lines where they fit without exceeding 80 columns.

1.13.0.0

Removed write and execute permissions from group/others on all *.m files.

1.12.0.0

Removed trailing whitespace and switched from 2 spaces after each period to 1 in the interest of readability.

1.11.0.0

Added space in title.

1.10.0.0

Made code available as a toolbox and removed some unnecessary hidden files.

1.9.0.0

A MATLAB user reported a crash on line 23 of RemoveEqualPairs.m. This change fixes the type mismatch error by converting a double to a uint32. GNU Octave users will be unaffected by this change as GNU Octave handles the type conversion automatically.

1.8.0.0

Fixes a serious bug in RemoveEqualPairs that resulted in a small number of latitude, longitude pairs being omitted from the final output of GridSphere. Big thanks to Francisco for the bug report.

1.7.0.0

n/a

1.5.0.0

Replaced tabs with spaces so that the source code displays consistently in all text editors.

1.4.0.0

Added usage example per user request.

1.3.0.0

Replaced the ElementWiseMax function with an equivalent built-in function.

1.2.0.0

Under the description, I added a link to the FindNearestNeighbors function.

1.1.0.0

Added a missing function file.

1.0.0.0