Code covered by the BSD License  

Highlights from
GridSphere

5.0

5.0 | 1 rating Rate this file 40 Downloads (last 30 days) File Size: 11.5 KB File ID: #28842

GridSphere

by Kurt

 

26 Sep 2010 (Updated 21 May 2012)

Produces a nearly even grid over the surface of a sphere.

| Watch this File

File Information
Description

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

Required Products MATLAB
MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
07 Feb 2012 Paul Koppen

Blazingly fast and well documented. Only an example would not have been unbecoming, e.g. to illustrate the fact that returned values are in degrees (whereas Matlab's sph2cart requires radians).

[lat,long] = GridSphere(1000);
latrad = deg2rad(lat);
longrad = deg2rad(long);
[x,y,z] = sph2cart(longrad, latrad, 1);
scatter3(x, y, z, 22);
axis equal vis3d;

08 Feb 2012 Kurt

Thank you for the feedback, Paul. I went ahead and put in a request for the description to be modified to include a usage example. It should appear within five business days.

16 May 2012 LU

Hi Kurt, Wonderful program. I was just wondering if it is possible to connect the vertices with lines? Using Paul's example plots the vertiecs but i would like to display it as a mesh grid showing the edges of the triangles.

Thanks!

19 May 2012 Kurt

Thank you, LU! That's a great question. How concerned are you concerned with performance? If you can stomach an O(n ^ 2) algorithm, where n is the number of points output by GridSphere, then I think the following approach will be easiest.

1. Find the distance between all the pairs of points output by GridSphere.
2. Sort by these distances to find all the pairs of points that are closest to one another. There are at least three gotchas here: (1) you'll need to make sure that either you're not computing the distance between a point and itself or that you're filtering out the pairs with distance 0, (2) you'll probably want to avoid computing both the distance from point a to point b and the distance from point b to point a, and (3) you'll need to account for the imperfect precision of floating point arithmetic, which will result in clumps of distances that are very close but not quite equal. Some of the functions that come with GridSphere may be helpful to you, such as DistinctFromPrevious, which will find the boundaries between the aforementioned clumps.
3. Draw great circles (or just straight lines) connecting the pairs of points you found in step 2. Each of these pairs corresponds to one edge of a triangle. As Paul mentioned, you may need to call conversion functions like deg2rad and sph2cart on your great circle (or line) vectors to project them appropriately.

Please login to add a comment or rating.
Updates
27 Sep 2010

Added a missing function file.

27 Sep 2010

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

10 Oct 2010

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

08 Feb 2012

Added usage example per user request.

21 May 2012

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

Tag Activity for this File
Tag Applied By Date/Time
grid Kurt 27 Sep 2010 10:05:06
sphere Kurt 27 Sep 2010 10:05:06
ball Kurt 27 Sep 2010 10:05:06
geometry Kurt 27 Sep 2010 10:05:06
geodesic Kurt 27 Sep 2010 10:05:06
find nearest neighbors on sphere Kurt 27 Sep 2010 18:56:43
findnearestneighbors Kurt 27 Sep 2010 18:57:02
sphere Asad 08 Jun 2011 03:16:51

Contact us at files@mathworks.com