Advertisement
Guest User

Untitled

a guest
Dec 27th, 2023
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. VectorOption? FindVectorOptionFor(Line line1, Line line2, int dx3, int dy3)
  2. {
  3.     long min = 0;
  4.     long max = 1000000000000;
  5.     long ycheck = long.MaxValue;
  6.     long xcheck = long.MaxValue;
  7.     long t1 = long.MaxValue;
  8.     long t2 = long.MaxValue;
  9.     while (ycheck != 0 && min != max)
  10.     {
  11.         long x1 = line1.StartPoint.X;
  12.         long dx1 = line1.Direction.X;
  13.         long x2 = line2.StartPoint.X;
  14.         long dx2 = line2.Direction.X;
  15.         long y1 = line1.StartPoint.Y;
  16.         long dy1 = line1.Direction.Y;
  17.         long y2 = line2.StartPoint.Y;
  18.         long dy2 = line2.Direction.Y;
  19.         t1 = ((max - min) / 2) + min;
  20.  
  21.         // Find t2
  22.         t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
  23.         ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
  24.         if (ycheck == 0)
  25.         {
  26.             xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
  27.             if (xcheck == 0)
  28.             {
  29.                 break;
  30.             }
  31.         }
  32.         else if (ycheck > 0)
  33.         {
  34.             min = t1;
  35.         }
  36.         else
  37.         {
  38.             max = t1;
  39.         }
  40.         if (max - min == 1)
  41.         {
  42.             t1 = min;
  43.             t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
  44.             ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
  45.             if (ycheck == 0)
  46.             {
  47.                 xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
  48.                 if (xcheck == 0)
  49.                 {
  50.                     break;
  51.                 }
  52.             }
  53.             t1 = max;
  54.             t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
  55.             ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
  56.             xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
  57.             break;
  58.         }
  59.     }
  60.     if (ycheck == 0 && xcheck == 0)
  61.     {
  62.         return new VectorOption(line1.StartPoint + line1.Direction * t1, line2.StartPoint + line2.Direction * t2, t1, t2);
  63.     }
  64.     else
  65.     {
  66.         return null;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement