public static AttackParameterModel CalculateAttackParameters(LineModel targetLine, double targetHeading, double subHeading, double attackDirection)
        {
            var actualAttackDirection = DirectionOperation.CalculateSubActualDirection(subHeading, attackDirection);

            var attackLine  = CalculateLineFromPointAndDirection(new PointModel(0, 0), actualAttackDirection);
            var attackPoint = CalculatePointByTwoLines(targetLine, attackLine);

            double aob = 0;

            if (actualAttackDirection < 180 && targetLine.b > 0)
            {
                if (targetLine.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    aob = 180 - Math.Abs(targetHeading - actualAttackDirection);
                }
                else
                {
                    aob = Math.Abs(targetHeading - actualAttackDirection);
                }
            }
            else if (actualAttackDirection < 360 && targetLine.b > 0)
            {
                if (targetLine.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    aob = Math.Abs(actualAttackDirection - targetHeading) - 180;
                }
                else
                {
                    aob = 180 - Math.Abs(actualAttackDirection - targetHeading);
                }
            }
            else if (actualAttackDirection < 180 && targetLine.b <= 0)
            {
                if (targetLine.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    aob = 180 - Math.Abs(actualAttackDirection - targetHeading);
                }
                else
                {
                    aob = Math.Abs(actualAttackDirection - targetHeading);
                }
            }
            else if (actualAttackDirection < 360 && targetLine.b > 0)
            {
                if (targetLine.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    aob = Math.Abs(targetHeading - actualAttackDirection);
                }
                else
                {
                    aob = 180 - Math.Abs(targetHeading - actualAttackDirection);
                }
            }

            return(new AttackParameterModel(attackPoint, Math.Round(aob, 2)));
        }
        private void PaintAttackLine(ref Graphics graphic, LineModel targetLine, double subHeading, double attackAngle)
        {
            Pen pen = new Pen(Color.Red, 2);
            var actualAttackAngle    = DirectionOperation.CalculateSubActualDirection(subHeading, attackAngle);
            var attackLine           = CoordinateSystemOperation.CalculateLineFromPointAndDirection(new PointModel(0, 0), actualAttackAngle);
            var attackInterceptPoint = CoordinateSystemOperation.CalculatePointByTwoLines(targetLine, attackLine);

            DrawLineByPoint(ref graphic, pen, new PointModel(0, 0), attackInterceptPoint);
            pen.Dispose();
        }
Exemple #3
0
        public static void CalculateSpeed(TextBox targetLengthText, TextBox targetHeadingText, TextBox subHeadingText, TextBox targetPassCenterTimeText, TextBox targetPassCenterDicretionText, ref TextBox targetSpeedText)
        {
            if (string.IsNullOrEmpty(targetLengthText.Text) || string.IsNullOrEmpty(targetPassCenterDicretionText.Text) || string.IsNullOrEmpty(targetHeadingText.Text) || string.IsNullOrEmpty(targetPassCenterTimeText.Text) || string.IsNullOrEmpty(subHeadingText.Text))
            {
                return;
            }

            double targetLength, targetPassCenterDirection, targetHeading, targetPassCenterTime, subHeading = 0;

            try
            {
                targetLength = Convert.ToDouble(targetLengthText.Text);
                targetPassCenterDirection = Convert.ToDouble(targetPassCenterDicretionText.Text);
                targetHeading             = Convert.ToDouble(targetHeadingText.Text);
                targetPassCenterTime      = Convert.ToDouble(targetPassCenterTimeText.Text);
                subHeading = Convert.ToDouble(subHeadingText.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + targetLengthText.Text + ", " + targetPassCenterDicretionText.Text + ", " + targetHeadingText.Text + ", " + targetPassCenterTimeText.Text + ", " + subHeadingText.Text);
                return;
            }

            double actualTargetPassCenterDirection = DirectionOperation.CalculateSubActualDirection(subHeading, targetPassCenterDirection);
            //if (targetPassCenterDirection > 180)
            //{
            //    actualTargetPassDirection = subHeading - (360 - targetPassCenterDirection);
            //}
            //else
            //{
            //    actualTargetPassDirection = subHeading + targetPassCenterDirection;
            //}
            double standardTargetHeading = actualTargetPassCenterDirection - 90;

            standardTargetHeading = DirectionOperation.CorrectDirection(standardTargetHeading);

            double targetTiltAngle = Math.Abs(targetHeading - standardTargetHeading);

            if (targetTiltAngle > 180)
            {
                targetTiltAngle = Math.Min(targetHeading, standardTargetHeading) + 360 - Math.Max(targetHeading, standardTargetHeading);
                DirectionOperation.CorrectDirection(targetTiltAngle);
            }
            double actualLength  = MathOperation.Cos(targetTiltAngle) * targetLength;
            double standardSpeed = Math.Round(actualLength / targetPassCenterTime * 1.94, 2);
            double targetSpeed   = standardSpeed / MathOperation.Cos(targetTiltAngle);

            targetSpeedText.Text = targetSpeed.ToString();
        }
        public static void CalculateDirectionLine(TextBox subHeadingText, TextBox directionText, TextBox observePos1PositionText, ref LineModel directionLine, ref TextBox directionLineText, bool isObservePos1DirectionLine = true)
        {
            if (string.IsNullOrEmpty(directionText.Text) || string.IsNullOrEmpty(subHeadingText.Text))
            {
                return;
            }

            double direction, subHeading;

            try
            {
                direction  = Convert.ToDouble(directionText.Text);
                subHeading = Convert.ToDouble(subHeadingText.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + directionText.Text + ", " + subHeadingText.Text);
                return;
            }

            direction = DirectionOperation.CalculateSubActualDirection(subHeading, direction);

            PointModel observePos = new PointModel(0, 0);

            if (isObservePos1DirectionLine && !string.IsNullOrEmpty(observePos1PositionText.Text))
            {
                observePos = PointModel.Parse(observePos1PositionText.Text);

                if (observePos == null)
                {
                    return;
                }
            }

            directionLine          = CoordinateSystemOperation.CalculateLineFromPointAndDirection(observePos, direction);
            directionLineText.Text = directionLine.ToString();
        }
        public static void CalculateTargetObservationPos(TextBox targetDirectionText, TextBox subDirectionText, TextBox observationHeightText, TextBox targetHeightText, ref TextBox distanceText, ref TextBox observationDateText, ref TextBox targetPositionText, bool updateObservationDate = true)
        {
            if (updateObservationDate)
            {
                observationDateText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }

            if (string.IsNullOrEmpty(targetHeightText.Text) || string.IsNullOrEmpty(observationHeightText.Text))
            {
                return;
            }

            double targetHeight, observationHeight = 0;

            try
            {
                targetHeight      = Convert.ToDouble(targetHeightText.Text);
                observationHeight = Convert.ToDouble(observationHeightText.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + targetHeightText.Text + ", " + observationHeightText.Height);
                return;
            }

            var distance = Math.Round(targetHeight / observationHeight * 400.00, 2);

            distanceText.Text = distance.ToString();

            if (string.IsNullOrEmpty(targetDirectionText.Text) || string.IsNullOrEmpty(subDirectionText.Text))
            {
                return;
            }

            double targetDirection = 0, subDirection = 0;

            try
            {
                targetDirection = Convert.ToDouble(targetDirectionText.Text);
                subDirection    = Convert.ToDouble(subDirectionText.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + targetDirectionText.Text + ", " + subDirectionText.Text);
            }

            var    actualDirection = DirectionOperation.CalculateSubActualDirection(subDirection, targetDirection);
            double xAxisAngle;
            int    quadrantIndex;

            if (actualDirection < 90)
            {
                xAxisAngle    = 90 - actualDirection;
                quadrantIndex = 1;
            }
            else if (actualDirection < 180)
            {
                xAxisAngle    = actualDirection - 90;
                quadrantIndex = 2;
            }
            else if (actualDirection < 270)
            {
                xAxisAngle    = 270 - actualDirection;
                quadrantIndex = 3;
            }
            else
            {
                xAxisAngle    = actualDirection - 270;
                quadrantIndex = 4;
            }

            var cos = MathOperation.Cos(xAxisAngle);
            var sin = MathOperation.Sin(xAxisAngle);
            var x   = cos * distance;
            var y   = sin * distance;

            if (quadrantIndex == 2)
            {
                y = -1 * y;
            }
            if (quadrantIndex == 3)
            {
                y = -1 * y;
                x = -1 * x;
            }
            if (quadrantIndex == 4)
            {
                x = -1 * x;
            }

            var point = new PointModel(x, y);

            targetPositionText.Text = point.ToString();
        }