public static void IntersectTest() { double deviation = -5.90659270237146; var a = new CoordinatePoint(new Coordinate(39.302384), new Coordinate(-84.3143165), 0); var aBearing = 146.51 + deviation; var b = new CoordinatePoint(new Coordinate(39.2972996666667), new Coordinate(-84.3152046666667), 0); var bBearing = 233.10 + deviation; //var a = new CoordinatePoint(new Coordinate(39,15,26.84), new Coordinate(-84,-17,-15.93), 0); //var aBearing = 90; //var b = new CoordinatePoint(new Coordinate( 39,15,35.25), new Coordinate( -84,-17,-11.84), 0); //var bBearing = 180; var intersection = CoordinatePointUtilities.FindIntersection(a, aBearing, b, bBearing); Console.WriteLine(intersection.Latitude.Value + "," + intersection.Longitude.Value); }
/// <inheritdoc /> public void SetMarkBearing(MarkType markType, double bearing, bool magneticBearing) { if (markType == MarkType.Course) { if (_state.Course == null || !(_state.Course is CourseByAngle)) { _state.Course = new CourseByAngle(); if (magneticBearing) { if (_state.StateValues.ContainsKey(StateValue.MagneticDeviation)) { (_state.Course as CourseByAngle).CourseAngle = bearing + _state.StateValues[StateValue.MagneticDeviation]; } else { _logger.Error("Cannot set course angle using magnetic bearing without magnetic deviation!"); return; } } else { (_state.Course as CourseByAngle).CourseAngle = bearing; } } } else if (_state.Location != null) { if (_state.Course == null || !(_state.Course is CourseByMarks)) { _state.Course = new CourseByMarks(); } Bearing fullBearing = new Bearing() { Location = _state.Location, RecordedAt = _state.BestTime, CompassHeading = bearing }; //compensate for magnetic deviation if (magneticBearing) { if (_state.StateValues.ContainsKey(StateValue.MagneticDeviation)) { fullBearing.CompassHeading = fullBearing.CompassHeading + _state.StateValues[StateValue.MagneticDeviation]; } else { _logger.Error("Cannot calculate mark location using magnetic bearing without magnetic deviation!"); return; } } _logger.Info(string.Format("Received bearing for {0} of {1:0.00} ({2:0.00} true) from {3},{4}, altitude {5}, deviation {6}", markType, bearing, fullBearing.CompassHeading, fullBearing.Location.Latitude.Value, fullBearing.Location.Longitude.Value, _state.StateValues[StateValue.AltitudeInMeters], _state.StateValues[StateValue.MagneticDeviation])); Mark mark; var course = _state.Course as CourseByMarks; if (!course.Marks.Any(x => x.MarkType == markType)) { mark = new Mark() { MarkType = markType, CaptureMethod = MarkCaptureMethod.Bearing, Location = null }; mark.Bearings = new List <Bearing>(); mark.Bearings.Add(fullBearing); course.Marks.Add(mark); State.TargetMark = mark; } else { mark = course.Marks.Where(x => x.MarkType == markType).Last(); mark.Bearings.Add(fullBearing); } if (mark.Bearings.Count > 1 && mark.CaptureMethod == MarkCaptureMethod.Bearing) { var bearing1 = mark.Bearings[mark.Bearings.Count - 2]; var bearing2 = mark.Bearings[mark.Bearings.Count - 1]; var location = CoordinatePointUtilities.FindIntersection(bearing1.Location, bearing1.CompassHeading, bearing2.Location, bearing2.CompassHeading); mark.Location = location; _logger.Info(string.Format("Calculated new location of {0} via bearings to be {1},{2}", markType, mark.Location.Latitude.Value, mark.Location.Longitude.Value)); //TODO, if there's more than 2, do we average down? } } }