public override float DistanceTo(PointF point) { if (this.Point1 == point || this.Point2 == point) { return 0; } // Calculate orhogonal line Line2D orthoLine = GetNormalLine(point); // Calculate Intersection PointF point3 = this.Intersection(orthoLine); // Calculate the length on the ortho segment if (point != point3) { Segment2D segment = new Segment2D(point, point3); return segment.Length(); } else { return 0; } }
public override float DistanceTo(PointF point) { if (this.Point1 == point || this.Point2 == point) { return 0; } // Calculate orhogonal line Line2D orthoLine = this.GetNormalLine(point); // Calculate Intersection PointF point3 = new Line2D(this.Point1, this.Point2).Intersection(orthoLine); if (this.ContainsAbsciss(point3.X)) { // Calculate the length on the ortho segment Segment2D segment = new Segment2D(point, point3); return segment.Length(); } else { Segment2D segment1 = new Segment2D(point, this.Point1); Segment2D segment2 = new Segment2D(point, this.Point2); return Math.Min(segment1.Length(), segment2.Length()); } }
private PointF FindClosestExtremum(PointF mouseValuePoint) { int selectedIndex = (int)Math.Round(mouseValuePoint.X); PointF returnPoint; Segment2D segment1, segment2; FloatSerie highSerie = highCurveType.DataSerie; FloatSerie lowSerie = lowCurveType.DataSerie; segment1 = new Segment2D(mouseValuePoint.X, mouseValuePoint.Y, selectedIndex, highSerie[selectedIndex]); segment2 = new Segment2D(mouseValuePoint.X, mouseValuePoint.Y, selectedIndex, lowSerie[selectedIndex]); if (segment1.Length() < segment2.Length()) { returnPoint = new PointF(selectedIndex, highSerie[selectedIndex]); } else { returnPoint = new PointF(selectedIndex, lowSerie[selectedIndex]); } return returnPoint; }