I have a problem I'm trying to develop a solution to. This is best for math parties, but I hope that there is already an existing library or a well-known algorithm that can work. Simply put, I have four shapes that will be laid out in a grid, and I'm trying to determine if they connect when the endpoints are aligned. Or in another way, think of a clock series. When the hands of one time zone are in the hands of another, they are “connected”. To extend the analogy, I have only 4 times ": 3:00, 6:15, 5:45, 9:00 (ignore what can be big versus a small hand). For the purpose of discussion, let's assume that the clock are aligned in rows, so limited connections are possible (in the final solution this clock will be aligned in the grid) I tried to apply various mathematical concepts to it, including simply identifying quandrants or hand numbering.I currently take a small approach and identify my hands clockwise, starting at noon (or straight up). I use 0 without handles in this place and 1 to indicate that there is a hand.

I created the diagrams below to represent the available connections and those that did not connect. I hope that it is obvious that in lines 3 and 4 of the diagram, those watches that have a connection will be aligned to the left of the “origin” clock.


To read the chart, take the first line as an example. The start clock will be connected to the two clock under “has a connection” (if each of them is immediately aligned to the right of the origin). A non-connected watch does not have a possible connection, regardless of whether it was aligned to the right or left of the origin.
The numbers are my current attempt to apply the pattern, but it can be a red herring because they really don't give me any help in developing the algorithm. Use or ignore them as you wish.
, , , . , , , .
FWIW, Javascript .