Beispiel #1
0
        public HealpixIndex GetHealpixIndex(HealpixPolarCoord polar)
        {
            if (polar.phi < 0)
            {
                polar.phi += (2.0 * Math.PI);
            }
            double i = Math.Sqrt((1.0 - Math.Cos(polar.theta)) * 3 * n2);

            if (Math.Cos(polar.theta) > 0)
            {
                // Northern Hemisphere
                return(GetHealpixIndexForNorthernHemisphere(polar));
            }
            else
            {
                // Southern Hemisphere
                HealpixPolarCoord polar_north = new HealpixPolarCoord()
                {
                    theta = Math.PI - polar.theta,
                    phi   = polar.phi
                };
                HealpixIndex temp = GetHealpixIndexForNorthernHemisphere(polar_north);  // mirror symmetry of the north
                temp.i = 4.0 * n - temp.i;
                return(temp);
            }
        }
Beispiel #2
0
        public Point3D GetCartesianCoord(HealpixPolarCoord polar)
        {
            double r = Math.Sin(polar.theta);

            return(new Point3D()
            {
                X = r * Math.Cos(polar.phi),
                Y = r * Math.Sin(polar.phi),
                Z = Math.Cos(polar.theta)
            });
        }
Beispiel #3
0
 // Generate sampling points on HEALPix
 //
 // OUT = GenerateSampling(n, mode)
 // Parameters
 // n : resolution of the grid (N_side)
 void GenerateSampling()
 {
     Points      = new Point3DCollection(n_total);
     PolarCoords = new HealpixPolarCoord[n_total];
     for (int pn = 0; pn < n_total; pn++)
     {
         HealpixIndex      index = GetNestedIndex(pn);
         HealpixPolarCoord polar = GetSphCoord(index);
         PolarCoords[pn] = polar;
         Point3D point = GetCartesianCoord(polar);
         Points.Add(point);
     }
 }
Beispiel #4
0
 // Convert spherical polar coordhinate to cartesian coordinate
 public HealpixPolarCoord GetSphCoord(HealpixIndex index)
 {
     if (index.i <= 2 * n)
     {
         // Northern Hemisphere
         return(GetNorthernHemisphere(index));
     }
     else
     {
         // Southern Hemisphere
         index.i = 4.0 * n - index.i;
         HealpixPolarCoord temp = GetNorthernHemisphere(index);  // mirror symmetry of the north
         temp.theta = Math.PI - temp.theta;
         return(temp);
     }
 }
Beispiel #5
0
        private void RedrawAllPieces2D()
        {
            // ------------------------------
            // Remove all pieces
            // ------------------------------
            canvas_projection_piece.Children.Clear();
            int n = rule.GetMaxIndex();

            for (int i = 0; i < n; i++)
            {
                PieceArray2D[i] = null;
            }

            // ------------------------------
            // Redraw all pieces
            // ------------------------------
            for (int i = 0; i < n; i++)
            {
                rule.SetCursorIndex(i);
                PieceKind piece = rule.GetPiece();
                if (piece == PieceKind.PIECE_EMPTY)
                {
                    continue;
                }

                // ------------------------------
                // 2D map cursor
                // ------------------------------
                Healpix.HealpixPolarCoord PolarCoord = rule.GetRegularizedCursorCoordinates();
                double azimuth, elevation;
                SphToMapTransform(PolarCoord.theta, PolarCoord.phi, out azimuth, out elevation);
                MapCursorTranslateB.X = azimuth;
                MapCursorTranslateB.Y = elevation;
                MapCursorB.Visibility = Visibility.Visible;

                switch (piece)
                {
                case PieceKind.PIECE_BLACK:
                    SetPiece2D(Colors.Black);
                    break;

                case PieceKind.PIECE_WHITE:
                    SetPiece2D(Colors.White);
                    break;
                }
            }
        }
Beispiel #6
0
        private void UpdatePiecesPositions2D()
        {
            int n = rule.GetMaxIndex();

            for (int i = 0; i < n; i++)
            {
                if (PieceArray2D[i] != null)
                {
                    rule.SetCursorIndex(i);

                    Healpix.HealpixPolarCoord PolarCoord = rule.GetRegularizedCursorCoordinates();
                    double azimuth, elevation;
                    SphToMapTransform(PolarCoord.theta, PolarCoord.phi, out azimuth, out elevation);

                    Ellipse            piece = (Ellipse)PieceArray2D[i];
                    TranslateTransform trans = (TranslateTransform)piece.RenderTransform;
                    trans.X  = azimuth;
                    trans.Y  = elevation;
                    trans.X -= piece.Width / 2;
                    trans.Y -= piece.Height / 2;
                }
                if (TerritoryArray2D[i] != null)
                {
                    rule.SetCursorIndex(i);

                    Healpix.HealpixPolarCoord PolarCoord = rule.GetRegularizedCursorCoordinates();
                    double azimuth, elevation;
                    SphToMapTransform(PolarCoord.theta, PolarCoord.phi, out azimuth, out elevation);

                    Rectangle          piece = (Rectangle)TerritoryArray2D[i];
                    TranslateTransform trans = (TranslateTransform)piece.RenderTransform;
                    trans.X  = azimuth;
                    trans.Y  = elevation;
                    trans.X -= piece.Width / 2;
                    trans.Y -= piece.Height / 2;
                }
            }
        }
Beispiel #7
0
        public HealpixIndex GetHealpixIndexForNorthernHemisphere(HealpixPolarCoord polar)
        {
            double temp_i = Math.Sqrt((1.0 - Math.Cos(polar.theta)) * 3 * n2);

            if (temp_i < n)
            {
                double i = Math.Sqrt((1.0 - Math.Cos(polar.theta)) * 3 * n2);
                return(new HealpixIndex()
                {
                    i = i,
                    j = polar.phi * 2.0 * i / Math.PI + 0.5
                });
            }
            else
            {
                double i = (4.0 / 3 - Math.Cos(polar.theta)) * (3 * n) / 2;
                double s = (i - n + 1) % 2;
                return(new HealpixIndex()
                {
                    i = i,
                    j = polar.phi * 2.0 * n / Math.PI + s / 2
                });
            }
        }