Hi Shubham,
As you want to calculate if two ellipses are overlapping or not and your code initializes the variables 'x0', 'y0', 'a0', 'b0', 'theta0' for the first ellipse, and 'x1', 'y1', 'a1', 'b1', 'theta1' for the second ellipse.
- The code first generates points on the first ellipse using the parameters 'a0', 'b0', and 'theta0'. Similarly, it generates points on the second ellipse using the parameters 'a1', 'b1', and 'theta1'.
- The function then selects points on the ellipses that could possibly overlap based on their orientations.
- It then calculates the closest point on each ellipse for each selected point.
- The function checks if any points on the second ellipse fall inside the first ellipse using a vector-based criterion.
- If there is an overlap, the variable overlap is set to 1; otherwise, it remains 0.
The tangent at each point on the ellipse is calculated to determine the orientation of the ellipse. And the reason for checking if the difference in tangent angles is greater than 90 degrees "diff(TAN) > pi/2" is to handle cases where the ellipses have a non-monotonic change in the tangent angle.
When the tangent angle changes rapidly, it indicates a change in the orientation of the ellipse. In such cases, there might be a possibility of the ellipse overlapping with itself due to a sharp change in its shape .
For the better visualization of overlapping you can plot "both the ellipses" and "the points that could possibly overlap" on the same figure, not the different ones.
For more information you can refer these documentations:
Hope it helps!