Ejemplo n.º 1
0
        public static (DoubleVector2, DoubleVector2) FindCollinearBounds(DoubleVector2 a, DoubleVector2 b, DoubleVector2 c)
        {
            var ab = a.To(b).SquaredNorm2D();
            var ac = a.To(c).SquaredNorm2D();
            var bc = b.To(c).SquaredNorm2D();

            if (ab > ac)
            {
                return(ab > bc ? (a, b) : (b, c));
            }
            else
            {
                return(ac > bc ? (a, c) : (b, c));
            }
        }
Ejemplo n.º 2
0
        public static bool TryFindNonoverlappingLineLineIntersectionT(DoubleVector2 a1, DoubleVector2 a2, DoubleVector2 b1, DoubleVector2 b2, out double tForA)
        {
            // via http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
            var p = a1;
            var r = a1.To(a2);
            var q = b1;
            var s = b1.To(b2);

            var rxs = Cross(r, s);

            if (rxs == 0) // iffy?
            {
                goto fail;
            }

            var qmp = q - p;
            var t   = Cross(qmp, s) / (double)rxs;

            tForA = t;
            return(true);

fail:
            tForA = Double.NaN;
            return(false);
        }
Ejemplo n.º 3
0
        private void InsertInternal(ref IntLineSegment2 s, double insertionThetaLower, double insertionThetaUpper, bool supportOverlappingLines)
        {
            if (insertionThetaLower == insertionThetaUpper)
            {
                return;
            }

            //         Console.WriteLine($"InsertInternal: {s}, {thetaLower} {thetaUpper}");

            // cull if wall faces away from origin
            var sperp = new DoubleVector2(s.Y2 - s.Y1, -(s.X2 - s.X1));
            var os1   = _origin.To(s.First.ToDoubleVector2());

            if (sperp.Dot(os1) < 0)
            {
                //return;
            }
            var rangeId = rangeIdCounter++;

            InsertInternalInternal(s, rangeId, insertionThetaLower, insertionThetaUpper, supportOverlappingLines, false);
        }