Search code examples
pythonmathspatialfoliumgeopy

I want to calculate overlap area from semicircle draw in map using python


I'm trying calculate overlap area created by semicircle which created by folium.after that i want to assign x,y,z value to the each semi semicircle by reduce same value overlap ex:- to reduce two x value semicircles
here is the image for better understand enter image description here

How do I calculate the overlap area using python?


Solution

  • 1. Pure Math:

    First, check if they intersect:

    Since the overlaps are not uniform (orthogonal, perpendicular or symmetrical) you are going to need to use the help of something called FUNCTIONS (like f(x)) and since your sectors (they are not a semi-circle) look to be the same size and have a internal area, you can use INEQUALITIES to check if they are intersecting.

    Say for example you have a two sectors that are intercepting like this, with their respective functions:

    f(x) = x^2 + y^2 <= 5 | {0 <= x <= 5} {0 <= y} (RED)

    g(x) = ((x - 4)^2) + y^2 <= 5 | {0 <= x <= 5} {0 <= y} (BLUE)

    link

    Assuming the unanimous cartesian system (x, y), all the sectors are drawing to the same coordinates (in the same 'space'; if you understand me here...):

    Just equate the 2 functions together:

    Rule: If f(x) intersects g(x) and vice-versa:

    1. f(x) = g(x) at some point
    2. g(x) is in / passes through the shaded area of f(x)
    3. f(x) is in / passes through the shaded area of g(x)
    4. The radius of f(x) + the radius of g(x) ≥ the distance between the 2 sectors

    Note: 2 & 3 might need calculus to check, if your functions are not inequalities but lines.

    enter image description here

    Since you are coding a program, you can do an early out, that if one of the top 4 conditions are not met, the sectors do not intersect.

    Second, if the sectors do intersect:

    Use intergral calculus to find the area of intersection:

    ∫f(x) - ∫g(x) = the magnitude (size) of the area (make sure the upper and lower limits are specified correctly)

    2. Using a 3D graphics method:

    Now, I know this is not a really good method for this, but you could implement collision detection, if you do not like heavy maths.

    Obviously, at first reading this may sound completely absurd (because collision detection is something used in game programming far more often), but have read at this:

    circle-circle collision

    and see if you can possibly implement a sort of sector hit-box on your quadrants (create circle hit-boxes, restrict them to sectors, and see if they intersect.)

    Honestly, though, the first method would be the most optimum, assuming if you have some form of 3D or 2D cartesian system, where your quadrants are mapped on.

    Although a little math heavy, it's up to you to how you would like to implement it in python (I would highly recommend creating multiple functions and optimising where you can (like the 4 rules to check intersection above)).

    If you do not know any of the math concepts, google them to find out more, cause knowing how they work would help you a lot...