Beispiel #1
0
        private static long CountBounces(LineD shot)
        {
            long numBounces = 0;
            LineD reflectedFrom = null;
            LineD lastReflectedFrom = null;
            PointD p = null;
            LineDIntersection intersect;
            do
            {
                // find intersection (try each of three lines)
                p = null; // reset
                reflectedFrom = null;
                if (p == null && lastReflectedFrom != TopLine)
                {
                    intersect = shot.GetIntersection(TopLine);
                    if (intersect.LinesIntersect)
                    {
                        p = intersect.Intersection;
                        reflectedFrom = TopLine;
                    }
                }
                if (p == null && lastReflectedFrom != LefLine)
                {
                    intersect = shot.GetIntersection(LefLine);
                    if (intersect.LinesIntersect)
                    {
                        p = intersect.Intersection;
                        reflectedFrom = LefLine;
                    }
                }
                if (p == null && lastReflectedFrom != RigLine)
                {
                    intersect = shot.GetIntersection(RigLine);
                    if (intersect.LinesIntersect)
                    {
                        p = intersect.Intersection;
                        reflectedFrom = RigLine;
                    }
                }

                // compute attack deltas.  Reverse the "horizontal" determined by orientation!!!

                // negate the "horizontal" element

                // compute the new line

                // increaseshot count
                numBounces++;
                lastReflectedFrom = reflectedFrom;
            } while (p != Origin);

            return numBounces;
        }
Beispiel #2
0
 private static void TestAndReportOnIntersection(LineD Line1, LineD Line2)
 {
     LineDIntersection hit = Line1.GetIntersection(Line2);
     Console.WriteLine();
     Console.WriteLine("Line1 {0}", Line1);
     Console.WriteLine("Line2 {0}", Line2);
     if (hit.LinesIntersect)
     {
         Console.WriteLine("Found Point {0}", hit.Intersection);
         Console.WriteLine("ua {0} ub {1}", hit.ua, hit.ub);
     }
     else
     {
         if (hit.LinesAreParallel)
             Console.WriteLine("Parallel");
         else if (hit.LinesAreCoincident)
             Console.WriteLine("Coincident");
         else
         {
             Console.WriteLine("ua {0} ub {1}", hit.ua, hit.ub);
             Console.WriteLine("May have hit, but not long enough!");
         }
     }
 }