public static void CalculateTargetLine(TextBox targetPos1Text, TextBox observeDate1Text, TextBox targetPos2Text, TextBox observeDate2Text, TextBox targetPos3Text, ref TextBox targetLineText, ref LineModel targetLine, ref TextBox targetHeadingText)
        {
            var pos1 = PointModel.Parse(targetPos1Text.Text);
            var pos2 = PointModel.Parse(targetPos2Text.Text);
            var pos3 = PointModel.Parse(targetPos3Text.Text);

            if (pos1 == null || pos2 == null)
            {
                return;
            }

            DateTime pos1Date, pos2Date;

            try
            {
                pos1Date = DateTime.ParseExact(observeDate1Text.Text, "yyyy-MM-dd HH:mm:ss", null);
                pos2Date = DateTime.ParseExact(observeDate2Text.Text, "yyyy-MM-dd HH:mm:ss", null);
            }
            catch
            {
                MessageBox.Show("invalid date time:" + observeDate1Text.Text + ", " + observeDate2Text.Text);
                return;
            }

            PointModel earlyPoint, laterPoint;

            if (pos1Date < pos2Date)
            {
                earlyPoint = pos1;
                laterPoint = pos2;
            }
            else
            {
                earlyPoint = pos2;
                laterPoint = pos1;
            }

            var line = CoordinateSystemOperation.CalculateLineFromTwoPoint(earlyPoint, laterPoint);

            targetLine          = line;
            targetLineText.Text = line.ToString();

            var targetHeading = CoordinateSystemOperation.CalculateDirectionFromLine(line);

            targetHeadingText.Text = targetHeading.ToString();
        }
        public static void CalculateActualTargetLine(LineModel randomTargetLine, LineModel estimatedDirectionLine, LineModel directionLine1, LineModel directionLine2, LineModel directionLine3, LineModel directionLine4, TextBox observePos1TimeDiffText, ref LineModel actualTargetLine, ref TextBox actualTargetLineText, ref PointModel targetConfirmedPoint, ref DateTime targetConfirmedPointDate, ref TextBox targetSpeedText)
        {
            if (randomTargetLine == null || estimatedDirectionLine == null || directionLine4 == null)
            {
                return;
            }

            targetConfirmedPoint      = CoordinateSystemOperation.CalculatePointByTwoLines(estimatedDirectionLine, directionLine4);
            targetConfirmedPointDate  = DateTime.Now;
            actualTargetLine          = CoordinateSystemOperation.CalculateLineFromSlopeAndPoint(randomTargetLine.a, targetConfirmedPoint, randomTargetLine.lineDirection);
            actualTargetLineText.Text = actualTargetLine.ToString();

            if (string.IsNullOrEmpty(observePos1TimeDiffText.Text) || directionLine1 == null || directionLine2 == null || directionLine3 == null)
            {
                return;
            }

            double time;

            try
            {
                time = Convert.ToDouble(observePos1TimeDiffText.Text);
            }
            catch
            {
                MessageBox.Show("invalid number: " + observePos1TimeDiffText.Text);
                return;
            }

            var intercept1   = CoordinateSystemOperation.CalculatePointByTwoLines(actualTargetLine, directionLine1);
            var intercept2   = CoordinateSystemOperation.CalculatePointByTwoLines(actualTargetLine, directionLine2);
            var intercept3   = CoordinateSystemOperation.CalculatePointByTwoLines(actualTargetLine, directionLine3);
            var length       = (CoordinateSystemOperation.CalculateLengthBetweenPoints(intercept1, intercept2) + CoordinateSystemOperation.CalculateLengthBetweenPoints(intercept2, intercept3)) / 2.00;
            var speedByMeter = length / time;
            var speedByKnot  = speedByMeter * 1.94;

            targetSpeedText.Text = Math.Round(speedByKnot, 2).ToString();

            var actualDirectionLine = CoordinateSystemOperation.CalculateLineFromTwoPoint(intercept1, intercept2);

            actualTargetLine.lineDirection = actualDirectionLine.lineDirection;
        }
        public static void CalculateEstimatedDirectionLine(LineModel directionLine1, LineModel directionLine2, LineModel directionLine3, LineModel randomTargetLine, TextBox observePos1Text, TextBox observePos1TimeDiffText, TextBox observePos2TimeDiffText, ref LineModel estimatedDirectionLine, ref TextBox estimatedDirectionLineText, ref TextBox targetHeadingText)
        {
            if (directionLine1 == null || directionLine2 == null || directionLine3 == null || randomTargetLine == null)
            {
                return;
            }

            double pos2LengthRatio = 1;

            if (!string.IsNullOrEmpty(observePos1TimeDiffText.Text) && !string.IsNullOrEmpty(observePos2TimeDiffText.Text))
            {
                try
                {
                    double pos1TimeDiff = Convert.ToDouble(observePos1TimeDiffText.Text);
                    double pos2TimeDiff = Convert.ToDouble(observePos2TimeDiffText.Text);
                    pos2LengthRatio = pos2TimeDiff / pos1TimeDiff;
                }
                catch
                {  }
            }

            var intercept1 = CoordinateSystemOperation.CalculatePointByTwoLines(directionLine1, randomTargetLine);
            var intercept2 = CoordinateSystemOperation.CalculatePointByTwoLines(directionLine2, randomTargetLine);
            var intercept3 = CoordinateSystemOperation.CalculatePointByTwoLines(directionLine3, randomTargetLine);

            var length1 = CoordinateSystemOperation.CalculateLengthBetweenPoints(intercept1, intercept2);
            var length2 = CoordinateSystemOperation.CalculateLengthBetweenPoints(intercept2, intercept3);
            var length  = (length1 + length2) / 2;

            length = length * pos2LengthRatio;

            LineDirection direction;

            if (intercept2.x > intercept1.x)
            {
                direction = LineDirection.LEFT_TO_RIGHT;
            }
            else
            {
                direction = LineDirection.RIGHT_TO_LEFT;
            }

            PointModel observePos = new PointModel(0, 0);

            if (!string.IsNullOrEmpty(observePos1Text.Text))
            {
                observePos = PointModel.Parse(observePos1Text.Text);
                if (observePos == null)
                {
                    return;
                }
            }

            var estimatedPoint = CoordinateSystemOperation.CalculatePointByLineAndLength(randomTargetLine, intercept3, length, direction);

            estimatedDirectionLine          = CoordinateSystemOperation.CalculateLineFromTwoPoint(observePos, estimatedPoint);
            estimatedDirectionLineText.Text = estimatedDirectionLine.ToString();

            var headingLine = CoordinateSystemOperation.CalculateLineFromTwoPoint(intercept1, intercept2);
            var heading     = CoordinateSystemOperation.CalculateDirectionFromLine(headingLine);

            targetHeadingText.Text = Math.Round(heading, 2).ToString();
        }