Beispiel #1
0
        public static SexagesimalAngle FromDouble(double angleInDegrees)
        {
            //ensure the value will fall within the primary range [-180.0..+180.0]
            while (angleInDegrees < -180.0)
            {
                angleInDegrees += 360.0;
            }

            while (angleInDegrees > 180.0)
            {
                angleInDegrees -= 360.0;
            }

            var result = new SexagesimalAngle
            {
                //switch the value to positive
                IsNegative = angleInDegrees < 0,
            };

            angleInDegrees = Math.Abs(angleInDegrees);

            //gets the degree
            result.Degrees = (int)Math.Floor(angleInDegrees);
            var delta = angleInDegrees - result.Degrees;

            //gets minutes and seconds
            var seconds = (int)Math.Floor(3600.0 * delta);

            result.Seconds = seconds % 60;
            result.Minutes = (int)Math.Floor(seconds / 60.0);
            delta          = (delta * 3600.0) - seconds;

            //gets fractions
            result.Milliseconds = (int)(1000.0 * delta);

            return(result);
        }
Beispiel #2
0
        public void AddFix(DateTime timestamp, double latitude, double longitude, int altitude)
        {
            var latDMS = SexagesimalAngle.FromDouble(latitude);
            var lonDMS = SexagesimalAngle.FromDouble(longitude);

            // ToDo: Ensure the length of the numbers does not exceed the format

            _sb.Append($"B{timestamp:HHmmss}");
            _sb.Append(string.Format(
                           "{0:00}{1:00}{2:000}{3}",
                           latDMS.Degrees,
                           latDMS.Minutes,
                           ((double)latDMS.Seconds / 60 + (double)latDMS.Milliseconds / 60000) * 1000,
                           latDMS.IsNegative ? 'S' : 'N'));

            _sb.Append(string.Format(
                           "{0:000}{1:00}{2:000}{3}",
                           lonDMS.Degrees,
                           lonDMS.Minutes,
                           ((double)lonDMS.Seconds / 60 + (double)lonDMS.Milliseconds / 60000) * 1000,
                           lonDMS.IsNegative ? 'W' : 'E'));

            _sb.AppendLine($"A{0:D5}{(int)Length.FromFeet(altitude).Meters:D5}002");
        }