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 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);
        }
Exemplo n.º 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();
        }