public static void CalculateSubObservePosition1(TextBox subHeadingText, TextBox odometer1Text, TextBox odometer2Text, ref TextBox observePosition1Text)
        {
            if (string.IsNullOrEmpty(subHeadingText.Text) || string.IsNullOrEmpty(odometer1Text.Text) || string.IsNullOrEmpty(odometer2Text.Text))
            {
                return;
            }

            double subHeading, odometer1, odometer2;

            try
            {
                subHeading = Convert.ToDouble(subHeadingText.Text);
                odometer1  = Convert.ToDouble(odometer1Text.Text);
                odometer2  = Convert.ToDouble(odometer2Text.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + subHeadingText.Text + ", " + odometer1Text.Text + ", " + odometer2Text.Text);
                return;
            }

            var reverseDirection = subHeading - 180;

            reverseDirection = DirectionOperation.CorrectDirection(reverseDirection);
            var reverseLine = CoordinateSystemOperation.CalculateLineFromPointAndDirection(new PointModel(0, 0), reverseDirection);
            var observePos1 = CoordinateSystemOperation.CalculatePointByLineAndLength(reverseLine, new PointModel(0, 0), Math.Abs(odometer2 - odometer1), reverseLine.lineDirection);

            observePosition1Text.Text = observePos1.ToString();
        }
        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();
        }
        public static LineModel CalculateRandomTargetLineByRotate(LineModel directionLine1, LineModel directionLine2, LineModel directionLine3)
        {
            var randomLength = 3000;
            var randomPoint  = CalculatePointByLineAndLength(directionLine2, new PointModel(0, 0), randomLength, directionLine2.lineDirection);

            var       startDirection        = CalculateDirectionFromLine(directionLine2);
            var       increaseDirectionStep = 0.01;
            double    increaseDirection     = 0;
            var       idealLengthDiff       = 0.01;
            LineModel result            = null;
            double    minimumLengthDiff = 99999999999;

            while (true)
            {
                increaseDirection = increaseDirection + increaseDirectionStep;
                if (increaseDirection >= 180)
                {
                    break;
                }
                if (minimumLengthDiff <= idealLengthDiff)
                {
                    break;
                }

                var candidateHeading = startDirection + increaseDirection;
                candidateHeading = DirectionOperation.CorrectDirection(candidateHeading);
                var candidateLine   = CalculateLineFromPointAndDirection(randomPoint, candidateHeading);
                var interceptPoint1 = CalculatePointByTwoLines(candidateLine, directionLine1);
                var interceptPoint3 = CalculatePointByTwoLines(candidateLine, directionLine3);

                var length1    = CalculateLengthBetweenPoints(interceptPoint1, randomPoint);
                var length2    = CalculateLengthBetweenPoints(interceptPoint3, randomPoint);
                var lengthDiff = Math.Abs(length1 - length2);

                //verify
                var intercept2 = CalculatePointByTwoLines(candidateLine, directionLine2);
                if (intercept2.x < -1000000 || intercept2.x > 1000000)
                {
                    continue;
                }
                if (lengthDiff == 0)
                {
                    continue;
                }

                if (lengthDiff < minimumLengthDiff)
                {
                    result            = candidateLine;
                    minimumLengthDiff = lengthDiff;
                }
            }

            return(result);
        }
Ejemplo n.º 5
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();
        }