Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VectorOption? FindVectorOptionFor(Line line1, Line line2, int dx3, int dy3)
- {
- long min = 0;
- long max = 1000000000000;
- long ycheck = long.MaxValue;
- long xcheck = long.MaxValue;
- long t1 = long.MaxValue;
- long t2 = long.MaxValue;
- while (ycheck != 0 && min != max)
- {
- long x1 = line1.StartPoint.X;
- long dx1 = line1.Direction.X;
- long x2 = line2.StartPoint.X;
- long dx2 = line2.Direction.X;
- long y1 = line1.StartPoint.Y;
- long dy1 = line1.Direction.Y;
- long y2 = line2.StartPoint.Y;
- long dy2 = line2.Direction.Y;
- t1 = ((max - min) / 2) + min;
- // Find t2
- t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
- ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
- if (ycheck == 0)
- {
- xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
- if (xcheck == 0)
- {
- break;
- }
- }
- else if (ycheck > 0)
- {
- min = t1;
- }
- else
- {
- max = t1;
- }
- if (max - min == 1)
- {
- t1 = min;
- t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
- ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
- if (ycheck == 0)
- {
- xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
- if (xcheck == 0)
- {
- break;
- }
- }
- t1 = max;
- t2 = FindT2(x1, dx1, x2, dx2, dx3, t1);
- ycheck = (y2 + t2 * dy2) - (y1 + t1 * dy1 + (t2 - t1) * dy3);
- xcheck = (x2 + t2 * dx2) - (x1 + t1 * dx1 + (t2 - t1) * dx3);
- break;
- }
- }
- if (ycheck == 0 && xcheck == 0)
- {
- return new VectorOption(line1.StartPoint + line1.Direction * t1, line2.StartPoint + line2.Direction * t2, t1, t2);
- }
- else
- {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement