/// <summary> /// Draws the scale ticks, with an invisible circle with r=MeterRadius bisecting each tick /// </summary> /// <param name="tickLength">The length of each tick</param> /// <param name="group">The geometry group to add each tick to</param> /// <param name="startAngle">The angle to start drawing ticks at, relative to the negative Y axis</param> private void DrawScale(double tickLength, GeometryGroup group, double startAngle = 0.0) { MeterTickPoints?.Clear(); if (Intervals == null) { return; } foreach (var interval in Intervals) { DrawInterval(interval, tickLength, group, startAngle); startAngle += (interval.EndDegree - interval.StartDegree) * (Math.PI / 180); } }
/// <summary> /// Draws an interval for the meter /// </summary> /// <param name="interval">The MeterRangeInteraval which represents this range of the meter</param> /// <param name="tickLength">The length of the ticks for this range</param> /// <param name="group">The geometry group to add this to add this to</param> /// <param name="startAngle"></param> private void DrawInterval(MeterRangeInterval interval, double tickLength, GeometryGroup group, double startAngle = 0.0) { double startRad = interval.StartDegree * (Math.PI / 180), endRad = interval.EndDegree * (Math.PI / 180); double radianInterval = (endRad - startRad) * (interval.TickInterval / (interval.EndValue - interval.StartValue)); var tickCount = (uint)((endRad - startRad) / radianInterval); for (var i = 0; i <= tickCount; i++) { var pathGeometry = new PathGeometry(); var figure = new PathFigure(); // draw tick line double x1 = MeterRadius * Math.Sin(startAngle), y1 = MeterRadius * Math.Cos(startAngle), x2 = (MeterRadius + tickLength) * Math.Sin(startAngle), y2 = (MeterRadius + tickLength) * Math.Cos(startAngle), labelX = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Sin(startAngle), labelY = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Cos(startAngle); figure.StartPoint = new Point(Radius + x1, Radius - y1); var line = new LineSegment { Point = new Point(Radius + x2, Radius - y2) }; MeterTickPoints?.Add(new TickPoint() { // midway point in the tick - the point the tick crosses the meter circle Point = new Point(Radius + (MeterRadius * Math.Sin(startAngle)), Radius - (MeterRadius * Math.Cos(startAngle))), LabelPoint = new Point(Radius + labelX, Radius - labelY), Value = i * interval.TickInterval + interval.StartValue }); figure.Segments.Add(line); pathGeometry.Figures.Add(figure); group.Children.Add(pathGeometry); startAngle += radianInterval; } }