Ejemplo n.º 1
0
        public CelestialGrid(int rows, int columns)
        {
            points  = new GridPoint[rows, columns];
            Rows    = rows;
            Columns = columns;

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    double latitude  = i * 10 - Rows / 2 * 10;
                    double longitude = j * 15;
                    points[i, j]             = new GridPoint(longitude, latitude);
                    points[i, j].RowIndex    = i;
                    points[i, j].ColumnIndex = j;
                }
            }
        }
Ejemplo n.º 2
0
        // TODO: move to separate renderer
        private void DrawGrid(Graphics g, Pen penGrid, CelestialGrid grid)
        {
            bool isAnyPoint = false;

            // Azimuths
            for (int j = 0; j < grid.Columns; j++)
            {
                var segments = grid.Column(j)
                               .Select(p => Angle.Separation(grid.ToHorizontal(p), Map.Center) < Map.ViewAngle * 1.2 ? p : null)
                               .Split(p => p == null, true);

                foreach (var segment in segments)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (segment.First().RowIndex > 1)
                        {
                            segment.Insert(0, grid[segment.First().RowIndex - 1, j]);
                        }
                    }

                    for (int k = 0; k < 2; k++)
                    {
                        if (segment.Last().RowIndex < grid.Rows - 2)
                        {
                            segment.Add(grid[segment.Last().RowIndex + 1, j]);
                        }
                    }

                    PointF[] refPoints = new PointF[2];
                    for (int k = 0; k < 2; k++)
                    {
                        var coord = grid.FromHorizontal(Map.Center);
                        coord.Longitude = segment[0].Longitude;
                        coord.Latitude += -Map.ViewAngle * 1.2 + k * (Map.ViewAngle * 2 * 1.2);
                        coord.Latitude  = Math.Min(coord.Latitude, 80);
                        coord.Latitude  = Math.Max(coord.Latitude, -80);
                        var refHorizontal = grid.ToHorizontal(coord);
                        refPoints[k] = Map.Projection.Project(refHorizontal);
                    }

                    DrawGroupOfPoints(g, penGrid, segment.Select(s => Map.Projection.Project(grid.ToHorizontal(s))).ToArray(), refPoints);

                    isAnyPoint = true;
                }
            }

            // Altitude circles
            for (int i = 0; i < grid.Rows; i++)
            {
                var segments = grid.Row(i)
                               .Select(p => Angle.Separation(grid.ToHorizontal(p), Map.Center) < Map.ViewAngle * 1.2 ? p : null)
                               .Split(p => p == null, true).ToList();

                // segment that starts with point "0 degrees"
                var seg0 = segments.FirstOrDefault(s => s.First().ColumnIndex == 0);

                // segment that ends with point "345 degrees"
                var seg23 = segments.FirstOrDefault(s => s.Last().ColumnIndex == 23);

                // join segments into one
                if (seg0 != null && seg23 != null && seg0 != seg23)
                {
                    segments.Remove(seg0);
                    seg23.AddRange(seg0);
                }

                foreach (var segment in segments)
                {
                    if (segment.Count == 24)
                    {
                        g.DrawClosedCurve(penGrid, segment.Select(s => Map.Projection.Project(grid.ToHorizontal(s))).ToArray());
                    }
                    else
                    {
                        for (int k = 0; k < 2; k++)
                        {
                            int col = segment.First().ColumnIndex;
                            if (col == 0)
                            {
                                segment.Insert(0, grid[i, 23]);
                            }
                            else
                            {
                                segment.Insert(0, grid[i, col - 1]);
                            }
                        }

                        for (int k = 0; k < 2; k++)
                        {
                            int col = segment.Last().ColumnIndex;

                            if (col < 23)
                            {
                                segment.Add(grid[i, col + 1]);
                            }
                            else if (col == 23)
                            {
                                segment.Add(grid[i, 0]);
                            }
                        }

                        PointF[] refPoints = new PointF[2];
                        for (int k = 0; k < 2; k++)
                        {
                            var coord = grid.FromHorizontal(Map.Center);
                            coord.Longitude += -Map.ViewAngle * 1.2 + k * (Map.ViewAngle * 1.2 * 2);
                            coord.Latitude   = segment[0].Latitude;
                            var refHorizontal = grid.ToHorizontal(coord);
                            refPoints[k] = Map.Projection.Project(refHorizontal);
                        }

                        if (!Geometry.IsOutOfScreen(refPoints[0], Map.Width, Map.Height) || !Geometry.IsOutOfScreen(refPoints[1], Map.Width, Map.Height))
                        {
                            refPoints = Geometry.LineRectangleIntersection(refPoints[0], refPoints[1], Map.Width, Map.Height);
                        }

                        DrawGroupOfPoints(g, penGrid, segment.Select(s => Map.Projection.Project(grid.ToHorizontal(s))).ToArray(), refPoints);
                    }

                    isAnyPoint = true;
                }
            }

            // Special case: there are no points visible
            // on the screen at the current position and zoom.
            // Then we select one point that is closest to screen senter.
            if (!isAnyPoint)
            {
                GridPoint closestPoint = grid.Points.OrderBy(p => Angle.Separation(grid.ToHorizontal(p), Map.Center)).First();

                {
                    var segment = new List <GridPoint>();
                    segment.Add(closestPoint);
                    int i = closestPoint.RowIndex;

                    for (int k = 0; k < 2; k++)
                    {
                        int col = segment.First().ColumnIndex;
                        if (col == 0)
                        {
                            segment.Insert(0, grid[i, 23]);
                        }
                        else
                        {
                            segment.Insert(0, grid[i, col - 1]);
                        }
                    }

                    for (int k = 0; k < 2; k++)
                    {
                        int col = segment.Last().ColumnIndex;

                        if (col < 23)
                        {
                            segment.Add(grid[i, col + 1]);
                        }
                        else if (col == 23)
                        {
                            segment.Add(grid[i, 0]);
                        }
                    }

                    PointF[] refPoints = new PointF[2];
                    for (int k = 0; k < 2; k++)
                    {
                        var coord = grid.FromHorizontal(Map.Center);
                        coord.Longitude += -Map.ViewAngle * 1.2 + k * (Map.ViewAngle * 1.2 * 2);
                        coord.Latitude   = segment[0].Latitude;
                        var refHorizontal = grid.ToHorizontal(coord);
                        refPoints[k] = Map.Projection.Project(refHorizontal);
                    }

                    if (!Geometry.IsOutOfScreen(refPoints[0], Map.Width, Map.Height) || !Geometry.IsOutOfScreen(refPoints[1], Map.Width, Map.Height))
                    {
                        refPoints = Geometry.LineRectangleIntersection(refPoints[0], refPoints[1], Map.Width, Map.Height);
                    }

                    DrawGroupOfPoints(g, penGrid, segment.Select(s => Map.Projection.Project(grid.ToHorizontal(s))).ToArray(), refPoints);
                }


                {
                    var segment = new List <GridPoint>();
                    segment.Add(closestPoint);
                    int j = closestPoint.ColumnIndex;

                    for (int k = 0; k < 2; k++)
                    {
                        if (segment.First().RowIndex > 1)
                        {
                            segment.Insert(0, grid[segment.First().RowIndex - 1, j]);
                        }
                    }

                    for (int k = 0; k < 2; k++)
                    {
                        if (segment.Last().RowIndex < grid.Rows - 2)
                        {
                            segment.Add(grid[segment.Last().RowIndex + 1, j]);
                        }
                    }

                    PointF[] refPoints = new PointF[2];
                    for (int k = 0; k < 2; k++)
                    {
                        var coord = grid.FromHorizontal(Map.Center);
                        coord.Longitude = segment[0].Longitude;
                        coord.Latitude += -Map.ViewAngle * 1.2 + k * (Map.ViewAngle * 2 * 1.2);
                        coord.Latitude  = Math.Min(coord.Latitude, 80);
                        coord.Latitude  = Math.Max(coord.Latitude, -80);
                        var refHorizontal = grid.ToHorizontal(coord);
                        refPoints[k] = Map.Projection.Project(refHorizontal);
                    }

                    DrawGroupOfPoints(g, penGrid, segment.Select(s => Map.Projection.Project(grid.ToHorizontal(s))).ToArray(), refPoints);
                }
            }
        }