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.