1

Below is the code, where inda and indb are rightmost point of polygon a and leftmost point of polygon b accordingly. Both the polygons are sorted in counter clockwise.

Orientation is a function that checks orientation of 3 point.

bool done = 0;

while (!done)
{
    done = 1;
    while (orientation(b[indb], a[inda], a[(inda+1)%n1]) >=0)
        inda = (inda + 1) % n1;

    while (orientation(a[inda], b[indb], b[(n2+indb-1)%n2]) <=0)
    {
        indb = (n2+indb-1)%n2;
        done = 0;
    }
}

I don't seem to understand the use of outer while loop using done for check, I think we shall find out the tangent without the outer loop.

Do correct me if I'm wrong.

Sneh Raval
  • 21
  • 2
  • 2
    [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – 463035818_is_not_an_ai Aug 02 '23 at 09:30
  • 1
    "I think we shall find out the tangent without the outer loop." what happened when you tried? – 463035818_is_not_an_ai Aug 02 '23 at 09:30
  • Do you mean "inda and indb are rightmost point of polygon a and rightmost point of polygon b" is the result of this code? `inda` and `indb` are variables that change their value, they cannot be rightmost point of the polygons initially, during and after this is executed – 463035818_is_not_an_ai Aug 02 '23 at 09:33
  • 1
    Your question is better than the downticking gives you credit for. However, it would be better with a diagram. Some sort of loop is required. e.g. traverse the right-most polygon (loop) until the tangent drops on or below some points of the other polygon (nested loop). For the points that the tangent dropped below find the smallest angle (loop). All fails when one polygon is contained within the other. – lastchance Aug 02 '23 at 09:57
  • I tried without outer loop, it worked, at least for some basic cases. I,m afraid it won't for some corner cases, I actually wanted to know about that if that was the case – Sneh Raval Aug 02 '23 at 18:01
  • @lastchance I was thinking something like that.. Plotting it would clear that.. thanks... – Sneh Raval Aug 02 '23 at 18:09

0 Answers0