1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Is it possible to divide points to regions only based on their minimum distance to...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I have a a set of scattered points with known coordinates on a plane (see schematic image), and four curves (C1-C4) that divide the whole plane into regions (R1-R5). I also know the minimum distance of each point to each curve. Is there a way to estimate which region the point falls into just based on this information? I would like to write code to do that in Python. My thinking is, to first find which minimum distance is the smallest for each point - that narrows down the options which region the point belongs to. But then how do I know which side of the curve the point falls on? For example, points A and B both have the smallest minimum distances d1 and d2 to curve C3, which would means they are either in region R3 or R4, but is there a way to narrow down which one? Curious to see if any solutions here are possible, or if more information is necessary to solve this problem. [​IMG]

    Edit: Here is an example code. I simplified it a bit. The data is stored in dataframe:

    columns = ['Point', 'x', 'y', 'd1','d2','R']
    data = [("A",1.5, 3.5, 1.2, 2.8, "NA"), ("B",3.5, 2.5, 0.8, 0.7, "NA"), ("C", 3.0, 0.5, 2.1,0.5,"NA")]
    df = pd.DataFrame(data, columns=columns)


    The region names are in a list:

    regions=["R1","R2","R3"]


    And output dataframe should be:

    output_columns = ['Point', 'x', 'y', 'd1','d2','R']
    output_data = [("A",1.5, 3.5, 1.2, 2.8, "R1"), ("B",3.5, 2.5, 0.8, 0.7, "R2"), ("C", 3.0, 0.5, 2.1,0.5,"R3")]
    output_df = pd.DataFrame(output_data, columns=output_columns)


    [​IMG]

    Continue reading...

Compartilhe esta Página