Reputation: 2045
I'm working on some logic for a labelling exercise.
I want to connect every red dot to a blue dot, but without the lines overlapping. (not as shown below)
I have a jsfiddle that generates dots and connects them here
https://jsfiddle.net/s1u7okd5/
enter code here
Red dots can vary, obviously, blue dots are fixed. I don't need someone to do the work for me, but I could do with some direction.
Questions:
1: I assume it's always possible to find a solution where the lines don't overlap (ignoring thickness of drawn line). Is this true?
2: I hoping to avoid a brute force approach. Is this possible?
Upvotes: 1
Views: 996
Reputation: 751
Assuming that the number of red dots (N) is equal to the number of blue dots (from pictures seems so), a quite naive solution can be:
Probably there can be some optimization, but this is anyway an iterative O(N^2) solution: much better than a brute force solution that, for example, use backtracking to explore all possibilities and find the right one.
Upvotes: 1