nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.26k stars 233 forks source link

2D voronoi with radius parameter #2161

Closed Durman closed 6 years ago

Durman commented 6 years ago

Result: https://github.com/nortikin/sverchok/files/1851743/voronoi.with.radius7_2018_03_27_11_29.zip I have sum thoughts about creating this algorithm: 2018-03-07_21-01-20 2018-03-07_21-02-18 2018-03-07_21-02-42 2018-03-07_21-03-03 Creating arc with two points and center: https://gist.github.com/b21c411afde560cf99c5b2f2589ad3c8 arck

vicdoval commented 6 years ago

I stepped through that output when I was coding "Contour 2D", but for the purpose of the node I deleted the separation lines. Probably this lines could be easily exposed to get this "voronoi arc" all the math is already inside the node And it works with weighted radius. screen

Durman commented 6 years ago

I allready have written something but didn't test it yet.)

def get_arc(start_v, end_v, center_v, resolution, mode='clockwise'):
    #return points of arc by two points and center of circle
    #resolution determines distanse between points of arc
    start_v, end_v = start_v - center_v, end_v - center_v
    start_angle = calc_angle(Vector((0,1)), start_v)
    #angle between start and end vectors
    angle = calc_angle(start_v, end_v)
    radius = get_distance(start_v, end_v)
    len_arc = get_len_arc(radius, angle)
    count = len_arc / resolution
    end_angle = start_angle + angle if mode == 'clockwise' else start_angle + angle - TWO_PI
    steps_angle = list(np.linspace(start_angle,end_angle,count))
    vectors = [Vector((sin(ang),cos(ang))) * radius + center_v for ang in steps_angle]
    return vectors

I think about how to keep data now. Just using lists is seemed too confusing. I think I will do two dictionary one for data of vectors and other for data of edges. Dictionary of vectors will keep information about neighbours of current point and something else maybe. Dictionary of edges will keep information about found chords of circles because there is no point to calculate chords for each point whose located on one edge. Something like that:

def get_structure_vert():
    dictionary = {'neibs':[],
                  'ang_neibs':[],
                  'sorted_neibs':[]}
    return dictionary

def get_structure_edg(edg):
    dictionary = {tuple(edg):{'height_chords':[],
                              'chords':[],
                              'intersect_chords':[]}}
    return dictionary

Nested dictionary also can get confuse :/

vicdoval commented 6 years ago

For sure you may found a faster/clearer way of doing it :D I keept the information in lists, is confusing but works (also with np).

I did a fast transformation from the contour2d into voronoiArc in case you want to test it, (It creates glitches in complicated situations) https://github.com/vicdoval/sverchok/tree/voronoi_arc_2d screen screen1

Maybe it is not even the same concept but looks similar isnt it? :D

Durman commented 6 years ago

I tested your node, it is really hard node, a lot of functions and code.)) And it works not as voronoi diagram now. The sense of voronoi is to have equal radius for each point otherwise diagram will not be voronoi. 1 voronoi sense_2018_03_10_04_38.gz I am going to make a more easy node. Main work will do delaunay triangulation, this algorithm we already have. After that I have to only find chords of circles and work will be done.))

vicdoval commented 6 years ago

:) I did my best clearing the code but you know.. If you want you can search about "variable radius voronoi" or "Weighted Voronoi diagram" it is a pretty interesting topic, maybe not part of what you are searching right now :D https://gist.github.com/81309cb5b52256b163d9e0a8ec6f7b5c voronoi sense_2018_03_10_04_39 voronoi sense_2018_03_10_04_38

Durman commented 6 years ago

It have appeared really hard goal for me in spite that all math stuff are clear. But however I managed to do something. It is far from the end yet.

chords

Durman commented 6 years ago

Something have gone wrong ))

arcs

Durman commented 6 years ago

2018-03-22_09-31-07

Durman commented 6 years ago

voronoi_2d_radius2 voronoi_2d_radius

Durman commented 6 years ago

It looks like nearly working. Process of implementation was really painful. I didn't use any articles about voronoi diagram so I faced with a lot of unpleasant surprises. And it is a little bit strange that it is working in the end. 2018-03-27_08-56-29

Durman commented 6 years ago

Ready for test. voronoi with radius7_2018_03_27_11_29.zip

Durman commented 6 years ago

Dividing to buildings based on this algorithm. 2018-03-28_16-37-43

Kosvor2 commented 6 years ago

@nortikin can you send @Durman invite for collaboration? no one have time to test things from outcomers. Sverchok is just an addon after all.

Durman commented 6 years ago

I don't think it is really necessary. I always can create pull request, isn't it? ))

Durman commented 6 years ago

2018-03-29_15-37-03 2018-03-29_15-39-44

Durman commented 6 years ago

2018-03-30_13-16-18

zeffii commented 6 years ago

lovely stuff @Durman !!

nortikin commented 6 years ago

invited

Kosvor2 commented 6 years ago

@Durman now you can create this template here: https://github.com/nortikin/sverchok/tree/master/node_scripts/SNLite_templates

Durman commented 6 years ago

Ok, I will do it soon.