public PointF?IntersectAtDistance(LineSegment segmentToCut, float width) { // always assuming other.A is the farthest end var distance = width * (line.IsAboveOrRightOf(segmentToCut.A) ? 1 : -1); var parallelLine = line.GetParallelLine(distance); var p = parallelLine.Intersect(segmentToCut.line); if (p.HasValue) { if (LineEquation.IsBetween(line.GetNormalAt(A), p.Value, line.GetNormalAt(B)) && segmentToCut.bindingRectangle.Contains(p.Value)) { return(p); } } List <PointF> points = new List <PointF>(); points.AddRange(segmentToCut.line.Intersect(new CircleEquation(width, A))); points.AddRange(segmentToCut.line.Intersect(new CircleEquation(width, B))); return(GetNearestPoint(segmentToCut.A, points)); }
public static bool IsBetween(LineEquation l1, PointF p, LineEquation l2) { return(l1.IsAboveOrRightOf(p) ^ l2.IsAboveOrRightOf(p)); }