Вася нарисовал n секторов на плоскости. Найдите площадь их объединения.
Входные данные
В входных данных находится ноль или более тестов, заканчивающихся концом файла. В первой строке каждого теста находится число число n - количество секторов, нарисованных Васей (1≤n≤500). Следующие n строк содержат 5 чисел: xi, yi, ri, si и αi, где (xi,yi) - центр круга, ri - его радиус, si - угол начала сектора в радианах (измеряется против часовой стрелки, начиная от оси OX), а αi - угол, образующий сектор. xi, yi, ri - целые числа (−100≤xi,yi≤100, 1≤ri≤100), s_i и ai - действительные числа, заданные с точностью до трех знаков после запятой (0≤si,αi≤6). Гарантируется, что сумма всех n не превосходит 500.
Выходные данные
Для каждого теста выведите ответ на задачу. Ответ будет принят системой, если абсолютная или относительная погрешность не превосходит 10^-6.
реши на языке C++, используя методы Вертикальные полосы переменной плотности + Сканлайн:
• Режем на полоски, которые дают элементарные элементарные огибающие. Можно порезать и сильнее.
• Каждая фигура идет от начала до конца полосы (то есть по горизонтали начинается и заканчивается либо на границе полосы, либо вне её).
• Внутри каждой полосы, заменяем каждую фигуру на прямоугольник, дальше сканлайном ищем площадь пересечения.
• Потом делим вертикальную линию пополам, проверяем хорошее ли получилось приближение, если плохое, запускаемся дальше.
Assistant
To solve the problem of finding the union area of multiple sectors on a plane, we'll employ a vertical scanline approach. This method involves dividing the plane into vertical strips based on critical x-coordinates where the union of sectors changes. For each strip, we'll compute the union of y-intervals covered by the active sectors and then sum these areas to obtain the total union area.
Here's a step-by-step breakdown of the approach:
Critical X-Coordinates: For each sector, identify critical x-coordinates where the sector's boundary intersects the vertical line. These include the leftmost and rightmost points of the sector's circle (x_i - r_i and x_i + r_i), and the x-coordinates where the sector's radial boundaries (defined by angles si and si + ai) intersect vertical lines.
Sorting and Removing Duplicates: Collect all these critical x-coordinates, sort them, and remove duplicates to form a list of unique x-values. These will define the vertical strips.
Processing Each Vertical Strip: For each interval between consecutive x-values:
Choose a representative x (x_mid) within the strip.
For each sector, determine if x_mid falls within its horizontal range (x_i - r_i to x_i + r_i). If it does, compute the corresponding y-intervals that lie within the sector at x_mid.
Collect all such y-intervals from all active sectors, merge overlapping intervals, and calculate the total covered y-length.
Multiply the y-length by the width of the strip (x_r - x_l) to get the area contribution from that strip.
Summing Up Areas: Accumulate the area contributions from all vertical strips to obtain the total union area.
Precision Handling: Ensure that floating-point calculations are handled with adequate precision to meet the problem's requirements.
The implementation below follows this approach meticulously, ensuring efficient computation even with up to 500 sectors.