Пример #1
0
        public PairIntDouble[] GetTerrainAndBiome(Coordinates[] coords)
        {
            DebugUtils.Assert(!ThreadDispatcher.IsMainThread);
            PairIntDouble[] ret = new PairIntDouble[coords.Length];

            ThreadDispatcher.QueueToMainThreadSync(() =>
            {
                for(int i = 0; i < coords.Length; i++)
                {
                    double lon = coords[i].Longitude;
                    double lat = coords[i].Latitude;

                    double alt = Body.pqsController.GetSurfaceHeight(Body.GetRelSurfaceNVector(lat * 180 / Math.PI, lon * 180 / Math.PI)) - Body.Radius;
                    int biome = -1;

                    if (Body.BiomeMap)
                    {
                        var attr = Body.BiomeMap.GetAtt(lat, lon);
                        for (int k = 0, n = Body.BiomeMap.Attributes.Length; k < n; k++)
                        {
                            if (attr == Body.BiomeMap.Attributes[k])
                            {
                                biome = k;
                                break;
                            }
                        }
                    }

                    ret[i] = new PairIntDouble(biome, alt);
                }
            });

            return ret;
        }
Пример #2
0
 public static Coordinates LinearCombination(double x, Coordinates u, double y, Coordinates v)
 {
     return new Coordinates(
         x * u.x + y * v.x,
         x * u.y + y * v.y,
         x * u.z + y * v.z
     );
 }
Пример #3
0
 public static double Distance(Coordinates u, Coordinates v)
 {
     return Math.Acos(Math.Min(1, u.x * v.x + u.y * v.y + u.z * v.z));
 }
Пример #4
0
        public Coordinates[] Grid(int resolution)
        {
            Coordinates[] ret = new Coordinates[1 + Vertices.Length * resolution * (resolution - 1) / 2];
            ret[0] = Center;
            int m = 1;

            for (int i = 0, j = Vertices.Length - 1; i < Vertices.Length; j = i++)
            {
                Coordinates u = Vertices[i];
                Coordinates v = Vertices[j];
                for (int k = 1; k < resolution; k++)
                {
                    for (int l = 0; l < k; l++)
                    {
                        ret[m++] = Coordinates.LinearCombination(l, u, k - l, v, resolution - 1 - k, Center);
                    }
                }
            }

            DebugUtils.Assert(m == ret.Length);

            return ret;
        }
Пример #5
0
 public TileGeometry(BinaryReader reader)
 {
     double lon = reader.ReadDouble();
     double lat = reader.ReadDouble();
     Center = new Coordinates(lat, lon);
     int n = reader.ReadInt32();
     Vertices = new Coordinates[n];
     Neighbours = new int[n];
     for (int i = 0; i < n; i++)
     {
         lon = reader.ReadDouble();
         lat = reader.ReadDouble();
         Vertices[i] = new Coordinates(lat, lon);
         Neighbours[i] = reader.ReadInt32();
     }
 }
Пример #6
0
        public TileGeometry(Coordinates[] vertices)
        {
            int nb = vertices.Length;
            Center = new Coordinates(vertices.Sum(i => i.x), vertices.Sum(i => i.y), vertices.Sum(i => i.z));

            Vertices = vertices.OrderBy(i => AngleAround(vertices[0].Vector, i.Vector, Center.Vector)).ToArray();
        }
Пример #7
0
 public Vertex(Coordinates c)
 {
     Coord = c;
 }
Пример #8
0
        Coordinates[] GetDual(int v)
        {
            var tri = vertices[v].Triangles.Where(i => triangles[i].Children == null).ToArray();

            Coordinates[] ret = new Coordinates[tri.Length];

            int j = 0;
            foreach (var i in tri)
            {
                DebugUtils.Assert((triangles[i].a == v || triangles[i].b == v || triangles[i].c == v));
                DebugUtils.Assert((vertices[triangles[i].a].Triangles.Contains(i)));
                DebugUtils.Assert((vertices[triangles[i].b].Triangles.Contains(i)));
                DebugUtils.Assert((vertices[triangles[i].c].Triangles.Contains(i)));
                DebugUtils.Assert(triangles[i].Children == null);

                ret[j++] = Coordinates.LinearCombination(
                    1, vertices[triangles[i].a].Coord,
                    1, vertices[triangles[i].b].Coord,
                    1, vertices[triangles[i].c].Coord);
            }

            return ret;
        }
Пример #9
0
 int AddVertex(Coordinates c)
 {
     vertices.Add(new Vertex(c));
     return vertices.Count - 1;
 }
Пример #10
0
        public List<int> FindTiles(Coordinates c, double distance, int hint = -1)
        {
            /*List<int> ret = new List<int>();
            ret.Add(FindTile(c, hint));

            while(true)
            {
                List<int> newtiles = ret.SelectMany(x => Tiles[x].Neighbours).Where(x => Coordinates.Distance(Tiles[x].Center, c) < distance && !ret.Contains(x)).ToList();
             				if (newtiles.Count == 0)
                    return ret;
                ret.AddRange(newtiles);
            }*/

            return Enumerable.Range(0, Tiles.Length).Where(x => Coordinates.Distance(Tiles[x].Center, c) < distance).ToList();
        }
Пример #11
0
        public int FindTile(Coordinates c, int hint = -1)
        {
            int[] indices;
            if (hint < 0)
            {
                indices = Enumerable.Range(0, Tiles.Length).ToArray();
            }
            else
            {
                var tmp = Tiles[hint].Neighbours;
                indices = new int[1 + tmp.Length];
                indices[0] = hint;
                for (int i = 0; i < tmp.Length; i++)
                    indices[i + 1] = tmp[i];
            }

            int bestidx = -1;
            double bestdist = double.MaxValue;
            foreach (int i in indices)
            {
                double dist = Coordinates.Distance(c, Tiles[i].Center);
                if (dist < bestdist)
                {
                    bestidx = i;
                    bestdist = dist;
                }
            }

            return bestidx;
        }
Пример #12
0
 public double[] GetTerrain(Coordinates[] coords)
 {
     return GetTerrainAndBiome(coords).Select(x => x.item2).ToArray();
 }