/// <summary> /// using previously accumulated LidarData, draws the boundaries of the scanned area. /// </summary> private void drawScannedArea() { if (numRays >= 2) { StringBuilder psb = new StringBuilder(); // the "Path" coordinates of the center of ray rotation: int centerX = (int)Math.Round(ScannedArea.ActualWidth / 2.0d); int centerY = (int)ScannedArea.ActualHeight; psb.AppendFormat("M{0},{1} ", centerX, centerY); foreach (int angleRaw in _lidarData.angles.Keys) { RangeReading reading = _lidarData.getLatestReadingAt(angleRaw); if (reading != null) { // 0 = full range, centerY = zero range double lineLength = reading.rangeMeters * ScannedArea.ActualHeight / rangeMaxValueM; double angleDegrees = reading.angleDegrees - (angleMaxValue - angleMinValue) / 2.0d; double angleRads = angleDegrees * Math.PI / 180.0d; int x1 = (int)Math.Round(lineLength * Math.Sin(angleRads)) + centerX; int y1 = -(int)Math.Round(lineLength * Math.Cos(angleRads)) + centerY; // Tracer.Trace("angle: " + angleDegrees + "/" + angleRads + " x=" + x1 + " y=" + y1); psb.AppendFormat("L{0},{1} ", x1, y1); } } psb.Append("z"); // Tracer.Trace(psb.ToString()); PathFigureCollectionConverter fcvt = new PathFigureCollectionConverter(); PathFigureCollection figures = (PathFigureCollection)fcvt.ConvertFromString(psb.ToString()); //"M200,200 L100,10 L100,10 L50,100 z"); ScannedArea.Data = new PathGeometry(figures); drawReferenceCircles(); } }