Advertisement
Guest User

Untitled

a guest
Dec 27th, 2023
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. IEnumerable<VectorOption> options = GenerateOptions(hailstones[0], hailstones[1]);
  2. foreach (Line hailstone in hailstones.Skip(2))
  3. {
  4.     options = FilterVectorOptions(hailstone, options);
  5. }
  6.  
  7. VectorOption? theOption = options.FirstOrDefault();
  8. if (theOption == null)
  9. {
  10.     Console.WriteLine("No solution found");
  11. }
  12. else
  13. {
  14.     Console.WriteLine($"Point found: {theOption.Line}");
  15.     Console.WriteLine(theOption.Line.StartPoint.AddAllDimensions());
  16. }
  17.  
  18. IEnumerable<VectorOption> GenerateOptions(Line line1, Line line2)
  19. {
  20.     for (int i = -500; i < 500; i++)
  21.     {
  22.         for (int j = -500; j < 500; j++)
  23.         {
  24.             VectorOption? option = FindVectorOptionFor(line1, line2, i, j);
  25.             if (option != null)
  26.             {
  27.                 yield return option;
  28.             }
  29.         }
  30.     }
  31. }
  32.  
  33. IEnumerable<VectorOption> FilterVectorOptions(Line hailstone, IEnumerable<VectorOption> vectorOptions)
  34. {
  35.     foreach (VectorOption option in vectorOptions)
  36.     {
  37.         (long time, Point point)? test = hailstone.Intersect(option.Line);
  38.         if (test.HasValue && test.Value.time >= 0)
  39.         {
  40.             yield return option;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement