Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect points of two types with lines without intersect?

How do I connect points from two sets of coordinates with lines without intersect any of the lines intersecting?

I have two types of points (a1, a2, ..., an, b1, b2, ..., bn), and their (x,y) coordinates.

Each one point in a and points b must be connected by a straight line at once such that none of the lines intersect.

How can this be done?

input (type, x, y):

a x y b x y a x y b x y

output (ax, ay, bx, by):

ax ay bx by ax ay bx, by

enter image description here

like image 248
user2821655 Avatar asked Sep 27 '13 01:09

user2821655


People also ask

What is it called when two lines intersect at a point?

When two lines share exactly one common point, they are called the intersecting lines. The intersecting lines share a common point. And, this common point that exists on all intersecting lines is called the point of intersection.

Can two lines intersect in two points?

Two lines in a plane, if they are not parallel, intersect in a point. Two lines or line segments cannot intersect each other in two points. They do so only in one point; In the figure below p, q, and r are parallel lines and E, A, and O are points on these parallel lines respectively.

How many points do two lines intersect?

Two distinct lines will always intersect in at most one point.


1 Answers

Here's an approach that I think is promising. Create a pairing of red and blue points (R1,B1), (R2,B2), .. (Rn,Bn). Then go through the list, and for each (Rj,Bj) draw a straight line Rj--Bj. If this line crosses any other line Ri--Bi already drawn, "uncross" these lines by replacing them with Ri--Bj and Rj--Bi (in effect changing your "bad" picture to your "good" picture).

You have to check whether these new lines cross any other existing lines, in which case you repeatedly perform the same "swap" and "crossing check" until there are no more crossing lines. You then go on to joining the pair after (Rj,Bj), and so on until you are done.

As noted in my other answer, a pairing of red and blue points that minimizes total edge length will also be crossing-free. In the approach given in this answer, note that every time you "uncross" edges you reduce the total of all the edge lengths. The algorithm most likely will not reach the pairing configuration with the minimum sum of edge lengths. However, the fact that the total edge lengths decrease with each swap implies that the algorithm will always terminate (i.e. you will not get into a repeating sequence of edge swaps).

like image 61
brainjam Avatar answered Oct 20 '22 09:10

brainjam