Exemplo n.º 1
0
        public LineHullPart(Pnt p0, Pnt p1)
        {
            _p0 = p0;
            _p1 = p1;

            _lin = new Lin2D(p0, p1);
        }
Exemplo n.º 2
0
        public bool Cut(HullLineArc line, ref double tMin, ref double tMax)
        {
            double angS = line.StartDirection;
            double r    = line.Radius;

            // Handle start point of line-arc
            var   aS         = new Pnt2D(r * Math.Cos(angS), r * Math.Sin(angS));
            Lin2D s          = line.Lin.GetParallel(aS);
            bool  intersects = CutLineThis(s.Ps, s.L, ref tMin, ref tMax);

            // Handle end point of line-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 |= CutLineThis(e.Ps, e.L, ref tMin, ref tMax);

            if (Angle.HasValue)
            {
                intersects |=
                    CutLineEndpoint(StartDirection + Angle.Value, line, ref tMin, ref tMax);

                intersects |= CutLineEndpoint(StartDirection, line, ref tMin, ref tMax);
            }

            intersects |= CutLineThis(line.Lin.Ps, line.Lin.L, ref tMin, ref tMax,
                                      new SignedHullLineArc(line, deflate: false));
            intersects |= CutLineThis(line.Lin.Ps, line.Lin.L, ref tMin, ref tMax,
                                      new SignedHullLineArc(line, deflate: true));
            return(intersects);
        }
Exemplo n.º 3
0
        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
                });
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        public Lin2D GetParallel(Pnt offset)
        {
            var parallel = new Lin2D(Ps + offset, Pe + offset);

            parallel._l2      = _l2;
            parallel._lNormal = _lNormal;
            parallel._dir     = _dir;

            return(parallel);
        }
Exemplo n.º 6
0
        public override IEnumerable <HullLine> GetHullLines(
            Lin2D lin, double meanOffset, bool atEnd)
        {
            double linDir   = Math.Atan2(lin.L.Y, lin.L.X);
            double startDir = atEnd ? linDir - Math.PI / 2 : linDir + Math.PI / 2;

            yield return(new HullLineArc
            {
                Lin = lin, Radius = meanOffset, StartDirection = startDir,
                Angle = Math.PI
            });
        }
Exemplo n.º 7
0
        public bool Cut(HullLineLine line, ref double tMin, ref double tMax)
        {
            // Handle start point of endPart
            Pnt   lS         = line.EndPart.Ps;
            Lin2D s          = line.Lin.GetParallel(lS);
            bool  intersects = CutLineThis(s.Ps, s.L, ref tMin, ref tMax);

            // Handle end point of endPart
            Pnt   lE = line.EndPart.Pe;
            Lin2D e  = line.Lin.GetParallel(lE);

            intersects |= CutLineThis(e.Ps, e.L, ref tMin, ref tMax);

            if (Angle.HasValue)
            {
                double r = _radius;
                // Handle start point of arc
                double angS = StartDirection;
                Pnt    aS   = new Pnt2D(r * Math.Cos(angS), r * Math.Sin(angS)) + _center - lS;
                Lin2D  eS   = line.EndPart.GetParallel(aS);
                intersects |= LineHullPart.CutLin(eS, e, ref tMin, ref tMax);

                // Handle end point of arc
                double angE = StartDirection + Angle.Value;
                Pnt    aE   = new Pnt2D(r * Math.Cos(angE), r * Math.Sin(angE)) + _center - lS;
                Lin2D  eE   = line.EndPart.GetParallel(aE);
                intersects |= LineHullPart.CutLin(eE, e, ref tMin, ref tMax);
            }

            // Handle tangents
            Pnt    eNormal = line.EndPart.LNormal;
            double dir     = Angle.HasValue
                                             ? Math.Atan2(eNormal.Y, eNormal.X)
                                             : double.NaN;

            if (!Angle.HasValue || IsInArcAngle(dir))
            {
                Lin2D eT0 = line.EndPart.GetParallel(_center + _radius * eNormal - lS);
                intersects |= LineHullPart.CutLin(eT0, e, ref tMin, ref tMax);
            }

            if (!Angle.HasValue || IsInArcAngle(dir + Math.PI))
            {
                Lin2D eT1 = line.EndPart.GetParallel(_center - _radius * eNormal - lS);
                intersects |= LineHullPart.CutLin(eT1, e, ref tMin, ref tMax);
            }

            return(intersects);
        }
Exemplo n.º 8
0
        public bool Cut(HullLineLine line, ref double tMin, ref double tMax)
        {
            Lin2D s          = line.Lin.GetParallel(line.EndPart.Ps);
            bool  intersects = CutLin(_lin, s, ref tMin, ref tMax);

            Lin2D e = line.Lin.GetParallel(line.EndPart.Pe);

            intersects |= CutLin(_lin, e, ref tMin, ref tMax);

            var thisAtStart = new Lin2D(_lin.Ps, _lin.Ps + line.EndPart.L);

            intersects |= CutLin(thisAtStart, e, ref tMin, ref tMax);

            var thisAtEnd = new Lin2D(_lin.Pe, _lin.Pe + line.EndPart.L);

            intersects |= CutLin(thisAtEnd, e, ref tMin, ref tMax);

            return(intersects);
        }
Exemplo n.º 9
0
        internal static bool CutLin(Lin2D lin, Lin2D other, ref double tMin, ref double tMax)
        {
            var    pair = new LinPair2D(lin, other);
            double fThis;

            if (pair.CutLineLine(out fThis))
            {
                if (fThis < 0 || fThis > 1)
                {
                    return(false);
                }

                Pnt    cut    = lin.Ps + fThis * lin.L;
                Pnt    lOther = cut - other.Ps;
                double fLine  = lOther * other.L / other.L2;

                tMin = Math.Min(tMin, fLine);
                tMax = Math.Max(tMax, fLine);
            }
            else
            {
                // Parallel
                if (fThis != 0)
                {
                    return(false);
                }

                Pnt    lThisS = lin.Ps - other.Ps;
                double fLine  = lThisS * other.L / other.L2;

                tMin = Math.Min(tMin, fLine);
                tMax = Math.Max(tMax, fLine);

                Pnt lThisE = lin.Pe - other.Ps;
                fLine = lThisE * other.L / other.L2;

                tMin = Math.Min(tMin, fLine);
                tMax = Math.Max(tMax, fLine);
            }

            return(true);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        private static IEnumerable <IHullPart> GetNeighborHullParts(Lin2D lin, SegmentHull hull)
        {
            Pnt leftOffset = hull.LeftOffset * lin.LNormal;

            yield return
                (new LineHullPart(lin.Ps + leftOffset, lin.Pe + leftOffset)
            {
                CutPart = CutPart.LeftSide
            });

            Pnt rightOffset = -hull.RightOffset * lin.LNormal;

            yield return
                (new LineHullPart(lin.Ps + rightOffset, lin.Pe + rightOffset)
            {
                CutPart = CutPart.RightSide
            });

            Pnt capOffset = (hull.LeftOffset - hull.RightOffset) / 2 * lin.LNormal;
            Pnt pCapS     = lin.Ps + capOffset;
            Pnt pCapE     = lin.Pe + capOffset;

            double meanOffset = (hull.LeftOffset + hull.RightOffset) / 2;

            foreach (IHullPart startPart in hull.StartCap.GetInflatedHullParts(
                         pCapS, pCapE, meanOffset, 0))
            {
                startPart.CutPart = CutPart.StartCap;
                yield return(startPart);
            }

            foreach (IHullPart endPart in hull.EndCap.GetInflatedHullParts(
                         pCapE, pCapS, meanOffset, 0))
            {
                endPart.CutPart = CutPart.EndCap;
                yield return(endPart);
            }
        }
Exemplo n.º 12
0
 public LinPair2D([NotNull] Lin2D l0, [NotNull] Lin2D l1)
     : base(l0, l1)
 {
 }
Exemplo n.º 13
0
 public abstract IEnumerable <HullLine> GetHullLines(
     Lin2D lin, double meanOffset, bool atEnd);