public static LineModel CalculateLineFromPointAndDirection(PointModel point, double direction)
        {
            double yAxisAngle;
            int    quadrant;

            if (direction < 90)
            {
                yAxisAngle = direction;
                quadrant   = 1;
            }
            else if (direction < 180)
            {
                yAxisAngle = 180 - direction;
                quadrant   = 2;
            }
            else if (direction < 270)
            {
                yAxisAngle = direction - 180;
                quadrant   = 3;
            }
            else
            {
                yAxisAngle = 360 - direction;
                quadrant   = 4;
            }

            var sin = MathOperation.Sin(yAxisAngle);
            var cos = MathOperation.Cos(yAxisAngle);
            var toNextPointLength = 100;
            //var nextPointX = sin * toNextPointLength + point.x;
            //var nextPointY = cos * toNextPointLength + point.y;
            double nextPointX, nextPointY;

            if (quadrant == 1 || quadrant == 2)
            {
                nextPointX = sin * toNextPointLength + point.x;
            }
            else
            {
                nextPointX = point.x - sin * toNextPointLength;
            }
            if (quadrant == 1 || quadrant == 4)
            {
                nextPointY = cos * toNextPointLength + point.y;
            }
            else
            {
                nextPointY = point.y - cos * toNextPointLength;
            }


            var nextPoint = new PointModel(nextPointX, nextPointY);
            var line      = CalculateLineFromTwoPoint(point, nextPoint);

            return(line);
        }
Пример #2
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 double CalculateDirectionFromLine(LineModel line)
        {
            var throughZeroLine = new LineModel(line.a, 0, line.lineDirection);

            double x = 100.00;
            var    y = throughZeroLine.CalculateY(x);

            if (y == 0)
            {
                return(0);
            }

            var tan   = Math.Abs(x / y);
            var angle = MathOperation.TanH(tan);

            if (line.a > 0)
            {
                var direction = angle;
                if (line.lineDirection == LineDirection.RIGHT_TO_LEFT)
                {
                    direction = direction + 180;
                }

                if (direction > 360)
                {
                    direction = direction - 360;
                }

                return(Math.Round(direction, 2));
            }
            else
            {
                var direction = 360 - angle;
                if (line.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    direction = direction - 180;
                }

                if (direction > 360)
                {
                    direction = direction - 360;
                }

                return(Math.Round(direction, 2));
            }
        }
        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();
        }