private static IEnumerable <HullLine> GetLineHullParts(Lin2D lin, SegmentHull hull) { Pnt leftOffset = hull.LeftOffset * lin.LNormal; yield return(new HullLineSimple { Lin = lin.GetParallel(leftOffset), CutPart = CutPart.LeftSide }); Pnt rightOffset = -hull.RightOffset * lin.LNormal; yield return(new HullLineSimple { Lin = lin.GetParallel(rightOffset), CutPart = CutPart.RightSide } ); double meanOffset = (hull.LeftOffset + hull.RightOffset) / 2; Pnt capOffset = (hull.LeftOffset - hull.RightOffset) / 2 * lin.LNormal; Lin2D centerLin = lin.GetParallel(capOffset); foreach (HullLine startPart in hull.StartCap.GetHullLines( centerLin, meanOffset, atEnd: false)) { startPart.CutPart = CutPart.StartCap; yield return(startPart); } foreach (HullLine endPart in hull.EndCap.GetHullLines(centerLin, meanOffset, atEnd: true)) { endPart.CutPart = CutPart.EndCap; yield return(endPart); } }
public override IEnumerable <HullLine> GetHullLines(Lin2D lin, double meanOffset, bool atEnd) { double l = atEnd ? _length : -_length; Pnt offset = l * lin.L; Pnt rOffset = -meanOffset * lin.LNormal; Pnt lOffset = meanOffset * lin.LNormal; yield return(new HullLineLine { Lin = lin.GetParallel(offset), EndPart = new Lin2D(rOffset, lOffset), }); if (Math.Abs(l) > 1.0e-8) { var endPart = new Lin2D(new Pnt2D(), offset); yield return (new HullLineLine { Lin = lin.GetParallel(lOffset), EndPart = endPart }); yield return (new HullLineLine { Lin = lin.GetParallel(rOffset), EndPart = endPart }); } }
public bool Cut(HullLineArc line, ref double tMin, ref double tMax) { double angS = line.StartDirection; double r = line.Radius; // Handle start point of arc var aS = new Pnt2D(r * Math.Cos(angS), r * Math.Sin(angS)); Lin2D s = line.Lin.GetParallel(aS); bool intersects = CutLin(_lin, s, ref tMin, ref tMax); // Handle end point of arc double angE = angS + line.Angle; var aE = new Pnt2D(r * Math.Cos(angE), r * Math.Sin(angE)); Lin2D e = line.Lin.GetParallel(aE); intersects |= CutLin(_lin, e, ref tMin, ref tMax); // Handle this start/end point intersects |= CutArcLine(_lin.Ps, line, ref tMin, ref tMax); intersects |= CutArcLine(_lin.Pe, line, ref tMin, ref tMax); // handle sides double arcAngle = GetNormedAngle(line.Angle); Pnt normal = _lin.LNormal; double normalDir = _lin.DirectionAngle + Math.PI / 2; // handle left side if (GetNormedAngle(normalDir - line.StartDirection) < arcAngle) { intersects |= CutLin(_lin.GetParallel(r * normal), line.Lin, ref tMin, ref tMax); } // handle right side if (GetNormedAngle(normalDir + Math.PI - line.StartDirection) < arcAngle) { intersects |= CutLin(_lin.GetParallel(-r * normal), line.Lin, ref tMin, ref tMax); } return(intersects); }