Exemplo n.º 1
0
 public void ClearData()
 {
     this.latInput     = "";
     this.longInput    = "";
     this.latHemi      = hemisphereNS.North;
     this.longHemi     = hemisphereEW.East;
     this.latitudeDeg  = 0;
     this.longitudeDeg = 0;
     this.latitudeRad  = 0;
     this.longitudeRad = 0;
 }
Exemplo n.º 2
0
            /* Coord data must have a latitude and longitude, and both hemispheres
             * Once we have these pieces, just set the other values for use later
             * Keep the values as degrees and radians for ease of use
             */
            public void SetNavCoords(String x, String y, hemisphereNS h1, hemisphereEW h2)
            {
                this.latInput  = x;
                this.longInput = y;
                this.latHemi   = h1;
                this.longHemi  = h2;

                this.latitudeDeg  = StringToNumber(latInput);
                this.longitudeDeg = StringToNumber(longInput);

                this.latitudeRad  = DegreesToRadians(latitudeDeg);
                this.longitudeRad = DegreesToRadians(longitudeDeg);
            }
Exemplo n.º 3
0
        private void CalculateNav()
        {
            #region dLongDistance

            /*
             * This section takes the longitude values, as decimals, as well as their respective hemispheres
             * and calculates the distance and which direction to go
             *
             * If the hemispheres are the same, the distance is simply the difference in the two longitudes
             * if they are different, the distance is (usually) the sum
             * however at this point if the distance is greater than 180 degrees, it is better to go the opposite direction
             * which will be 360 degrees - the previously calculated distance
             */
            if (StartCoord.longHemi == EndCoord.longHemi)
            {
                dLongDistance = Math.Abs(StartCoord.longitudeRad - EndCoord.longitudeRad);
            }
            else
            {
                dLongDistance = StartCoord.longitudeRad + EndCoord.longitudeRad;
                if (dLongDistance > Math.PI)
                {
                    dLongDistance = (2 * Math.PI) - dLongDistance;
                }
            }
            #endregion
            #region dLongDirection

            /*
             * This function determines if we should be going East or West to get to point B
             * 's' is just used as a temporary string
             *
             * for this function, we need to know the starting/final longitude, the hemispheres, and the distance
             * we check first if we are staying in the same hemisphere
             * if so, are we in the east or west, then evaluate which is greater or farther, then we know the direction
             */
            if (StartCoord.longHemi == EndCoord.longHemi)
            {
                if (StartCoord.longHemi == hemisphereEW.East)
                {
                    if (StartCoord.longitudeRad < EndCoord.longitudeRad)
                    {
                        dLongDirection = hemisphereEW.East;
                    }
                    else
                    {
                        dLongDirection = hemisphereEW.West;
                    }
                }
                else
                {
                    if (StartCoord.longitudeRad > EndCoord.longitudeRad)
                    {
                        dLongDirection = hemisphereEW.East;
                    }
                    else
                    {
                        dLongDirection = hemisphereEW.West;
                    }
                }
            }
            else
            {
                if ((StartCoord.longitudeRad + EndCoord.longitudeRad) > Math.PI)
                {
                    if (StartCoord.longHemi == hemisphereEW.East)
                    {
                        dLongDirection = hemisphereEW.East;
                    }
                    else
                    {
                        dLongDirection = hemisphereEW.West;
                    }
                }
                else
                {
                    if (StartCoord.longHemi == hemisphereEW.East)
                    {
                        dLongDirection = hemisphereEW.West;
                    }
                    else
                    {
                        dLongDirection = hemisphereEW.East;
                    }
                }
            }
            #endregion
            #region TotalDistance
            //If the lattitudes are in the same hemisphere, we add the cos and sin, else we subtract
            if (StartCoord.latHemi == EndCoord.latHemi)
            {
                totalDistance = Math.Round(60 * (180 / Math.PI) * (Math.Acos(Math.Cos(dLongDistance) * Math.Cos(StartCoord.latitudeRad) * Math.Cos(EndCoord.latitudeRad) + Math.Sin(StartCoord.latitudeRad) * Math.Sin(EndCoord.latitudeRad))), 1);
            }
            else
            {
                totalDistance = Math.Round(60 * (180 / Math.PI) * (Math.Acos(Math.Cos(dLongDistance) * Math.Cos(StartCoord.latitudeRad) * Math.Cos(EndCoord.latitudeRad) - Math.Sin(StartCoord.latitudeRad) * Math.Sin(EndCoord.latitudeRad))), 1);
            }
            #endregion
            #region InitialCourse

            /*
             * To calculate the initial course, we need to work out 3 values, known in navigation as A, B, and C values
             * The sign of the value is irrelevant, but the 'name' ie North/South is needed
             */
            icAValue = Math.Abs(Math.Tan(StartCoord.latitudeRad) / Math.Tan(dLongDistance));
            icBValue = Math.Abs(Math.Tan(EndCoord.latitudeRad) / Math.Sin(dLongDistance));

            icBDirection = EndCoord.latHemi; //B always same name as latitude

            //A is named opposite to lattitude, unless dlong between 90 and 270 degrees
            if (dLongDistance > (Math.PI / 2) && dLongDistance < (Math.PI * 1.5))
            {
                icADirection = StartCoord.latHemi;
            }
            else
            {
                if (StartCoord.latHemi == hemisphereNS.North)
                {
                    icADirection = hemisphereNS.South;
                }
                else
                {
                    icADirection = hemisphereNS.North;
                }
            }

            /*If A and B are same names, C is A + B and same direction
             * If different names, ie A is North and B is South, C takes the name of the greater value
             * and takes the value of the difference of A and B
             */
            if (icADirection == icBDirection)
            {
                icCValue     = icAValue + icBValue;
                icCDirection = icADirection;
            }
            else
            {
                icCValue = Math.Abs(icAValue - icBValue);
                if (icAValue > icBValue)
                {
                    icCDirection = icADirection;
                }
                else
                {
                    icCDirection = icBDirection;
                }
            }

            /* Tan (Initial Course) = 1 / (C*CosLatA)
             * This gives us the initial course as a Quadrantal ie North 30 Degrees East or South 50 Degrees West
             * So need to convert to Degrees True based on C direction and our DLong direction
             */
            initialCourseQuad = Convert.ToInt32((180 / Math.PI) * (Math.Atan(1 / (icCValue * Math.Cos(StartCoord.latitudeRad)))));
            if (icCDirection == hemisphereNS.North)
            {
                if (dLongDirection == hemisphereEW.East)
                {
                    initialCourseTrue = initialCourseQuad;
                }
                else
                {
                    initialCourseTrue = 360 - initialCourseQuad;
                }
            }
            else
            {
                if (dLongDirection == hemisphereEW.East)
                {
                    initialCourseTrue = 180 - initialCourseQuad;
                }
                else
                {
                    initialCourseTrue = 180 + initialCourseQuad;
                }
            }
            #endregion
            #region Vertex

            /* To calculate the vertex we need the dLong - distance from Start to Vertex
             * We also need to know which hemisphere we are in and direction we are going
             */

            dLongAV = Math.Abs(Math.Atan(1 / (Math.Tan((initialCourseQuad / (180 / Math.PI))) * Math.Sin(StartCoord.latitudeRad))));

            if (StartCoord.latHemi == icCDirection && dLongDirection == StartCoord.longHemi)
            {
                Vertex1Coord.SetLongitudeFromRad(StartCoord.longitudeRad + dLongAV);
            }
            else if (StartCoord.latHemi == icCDirection && dLongDirection != StartCoord.longHemi)
            {
                Vertex1Coord.SetLongitudeFromRad(StartCoord.longitudeRad - dLongAV);
            }
            else if (StartCoord.latHemi != icCDirection && dLongDirection == StartCoord.longHemi)
            {
                Vertex1Coord.SetLongitudeFromRad(StartCoord.longitudeRad - dLongAV);
            }
            else // if(StartCoord.latHemi == icCDirection && dLongDirection != StartCoord.longHemi)
            {
                Vertex1Coord.SetLongitudeFromRad(StartCoord.longitudeRad + dLongAV);
            }

            //Setting an initial hemisphere, can be changed later
            Vertex1Coord.longHemi = hemisphereEW.East;

            //If the longitude is < 0 or > 180 degrees we change the hemisphere
            if (Vertex1Coord.longitudeRad > Math.PI || Vertex1Coord.longitudeRad < 0)
            {
                Vertex1Coord.longitudeRad = Math.Abs(Vertex1Coord.longitudeRad);
                if (Vertex1Coord.longHemi == hemisphereEW.East)
                {
                    Vertex1Coord.longHemi = hemisphereEW.West;
                }
                else
                {
                    Vertex1Coord.longHemi = hemisphereEW.East;
                }
            }

            Vertex1Coord.latHemi = StartCoord.latHemi;
            Vertex1Coord.SetLatitudeFromRad(Math.Acos((Math.Sin(initialCourseQuad / (180 / Math.PI))) * Math.Cos(StartCoord.latitudeRad)));
            #endregion
            #region Vertex2

            /* Set the coordinates for Vertex 2, which are directly opposite the sphere of Vertex 1
             * The value for Latitude will remain the same, but hemisphere is swapped
             *
             * Longitude hemisphere will also be swapped, but the value will be 180 Degrees - Vertex 1
             *
             */

            Vertex2Coord.SetLatitudeFromRad(Vertex1Coord.latitudeRad);
            if (Vertex1Coord.latHemi == hemisphereNS.North)
            {
                Vertex2Coord.latHemi = hemisphereNS.South;
            }
            else
            {
                Vertex2Coord.latHemi = hemisphereNS.North;
            }

            Vertex2Coord.SetLongitudeFromRad(Math.PI - Vertex1Coord.longitudeRad);
            if (Vertex1Coord.longHemi == hemisphereEW.East)
            {
                Vertex2Coord.longHemi = hemisphereEW.West;
            }
            else
            {
                Vertex2Coord.longHemi = hemisphereEW.East;
            }
            #endregion
        }