private PointF?CalculateWithMirrorPositions2(List <SignalEventDetails> orderedGroup) { PointF?eventPosition = null; int groupCount = orderedGroup.Count; var detectionMirrors = new List <Tuple <PointF, PointF> >(groupCount); int totalSignalWeight = 0; for (int i = 0; i < groupCount; i++) { var signalEventDetails = orderedGroup[i]; signalEventDetails.Distance = _signalToDistanceConverter.GetDistance(signalEventDetails.Rssi); var otherSignalEventDetails = i < groupCount - 1 ? orderedGroup[i + 1] : orderedGroup[i - 1]; double angle = GeometryUtil.GetAngle(signalEventDetails.BleReceiver.Position, otherSignalEventDetails.BleReceiver.Position); var mirrors = CreateMirroredPoints(signalEventDetails.BleReceiver.Position, signalEventDetails.Distance, angle); detectionMirrors.Add(mirrors); totalSignalWeight += signalEventDetails.Rssi; } //get first mirror closest to leading sensor then advance to each mirror closest to event position for (int i = 1; i < groupCount - 1; i++) { var signalEventDetails = orderedGroup[i]; var nextMirrors = detectionMirrors[i + 1]; PointF refPosition; if (eventPosition.HasValue) { refPosition = eventPosition.Value; } else { refPosition = signalEventDetails.BleReceiver.Position; } var selectedNextPoint = GeometryUtil.GetDistance(nextMirrors.Item1, refPosition) < GeometryUtil.GetDistance(nextMirrors.Item2, refPosition) ? nextMirrors.Item1 : nextMirrors.Item2; if (!eventPosition.HasValue) { var currentMirrors = detectionMirrors[i]; refPosition = GeometryUtil.GetDistance(currentMirrors.Item1, selectedNextPoint) < GeometryUtil.GetDistance(currentMirrors.Item2, selectedNextPoint) ? currentMirrors.Item1 : currentMirrors.Item2; } eventPosition = GeometryUtil.CalculatePointInBetween(refPosition, selectedNextPoint); } return(eventPosition); }
private void HandleEventGroup(List <SignalEventDetails> eventGroup) { if (eventGroup.IsNullOrEmpty()) { return; } var groupCount = eventGroup.Count; var signalEventDetails = eventGroup.First(); var transmitter = eventGroup.First().Transmitter; PointF?eventPosition; if (groupCount == 1) { eventPosition = signalEventDetails.BleReceiver.Position; } else { var orderedGroup = eventGroup.OrderByDescending(e => e.Rssi).ToList(); signalEventDetails = orderedGroup.First(); eventPosition = _useWeightedPath ? CalculateWeightedPathPoint(orderedGroup) : CalculateWithMirrorPositions(orderedGroup); } if (!eventPosition.HasValue) { return; } if (!transmitter.PositionInitialized) { transmitter.Position = eventPosition.Value; } else { if (_useWeightedPath) { double distanceFromSource; var path = FindPath(signalEventDetails.BleReceiver, transmitter.Position, out distanceFromSource); if (path == null) { transmitter.Position = GeometryUtil.CalculatePointInBetween(transmitter.Position, eventPosition.Value); } else { distanceFromSource = distanceFromSource + (path.Distance - distanceFromSource) / 2; var newPoint = path.FindPointInPath(path.GetOther(signalEventDetails.BleReceiver), distanceFromSource); transmitter.Position = newPoint; } } else { transmitter.Position = GeometryUtil.CalculatePointInBetween(transmitter.Position, eventPosition.Value); } } if (TransmitterPositionDiscovered != null) { TransmitterPositionDiscovered(transmitter); } return; //can't order by timestamp because it's too random and created by the server //transmitter.Position = eventPosition.Value; //if (TransmitterPositionDiscovered != null) // TransmitterPositionDiscovered(transmitter); }
private PointF?CalculateWithMirrorPositions(List <SignalEventDetails> orderedGroup) { return(GeometryUtil.CalculatePointInBetween(orderedGroup[0].BleReceiver.Position, orderedGroup[1].BleReceiver.Position)); }