Exemple #1
0
            private Vector3d getPosition(Cell.Dictionary <Vector3d> cache)
            {
                if (IsPentagon)
                {
                    if (IsNorth)
                    {
                        return(new Vector3d(0, 1, 0));
                    }
                    if (IsSouth)
                    {
                        return(new Vector3d(0, -1, 0));
                    }

                    int n   = grid.n;
                    var lat = Math.Atan(0.5);
                    var lon = X * 2 * Math.PI / 5;
                    if (Y == 2 * n - 1)
                    {
                        lat  = -lat;
                        lon += Math.PI / 5;
                    }
                    return(new Vector3d(Math.Cos(lat) * Math.Cos(lon), Math.Sin(lat), Math.Cos(lat) * Math.Sin(lon)));
                }
                else
                {
                    var first  = getFirstParent();
                    var second = getSecondParent(first);
                    return((first.GetPosition(cache) + second.GetPosition(cache)).normalized);
                }
            }
Exemple #2
0
 public Vector3d GetPosition(Cell.Dictionary <Vector3d> cache)
 {
     if (!cache.ContainsKey(this))
     {
         cache[this] = getPosition(cache);
     }
     return(cache[this]);
 }
Exemple #3
0
        /// <summary>
        /// Creates a new geodesic grid with the given number of triangle subdivisions.
        /// </summary>
        /// <param name="subdivisions">Number of times to subdivide triangles.</param>
        public GeodesicGrid(int subdivisions)
        {
            this.n         = 1 << subdivisions;
            this.positions = new Cell.Map <Vector3>(subdivisions);

            var cache = new Cell.Dictionary <Vector3d>(subdivisions);

            foreach (var cell in this)
            {
                positions[cell] = (Vector3)cell.GetPosition(cache);
            }
        }