Polygons tree building by segments linking - algorithm

Suppose a set of 2d polygons is given.
What I am trying to do is to link all the polygons together by segments in a such way that:
each of the segments does not intersect any polygons in between (i.e. it connects the "visible" points of the polygon)
the path along the segments from one polygon to another does not have any loops(if you consider polygons to be the nodes of the graph and the segments to be the edges then the graph has no cycles, i.e. there is a tree of polygons).
For example:
At the moment I am solving the problem by brute force search of the segments from each polygon to all the others checking if there is no intersections in between. And then I am using Kruskal algorithm to find a tree, so the path could be constructed. The solution is ok for "simple" polygons but quite time consuming for more complex ones when the number of vertices and polygons is big.
Are there similar problems or better solutions to this problem ?

Related

Algorithm to generate a network that fills a 10x10 grid with a source, horizontal lines, right angles, t-junctions and nodes?

Just for fun I'm trying to create a non-flash version of http://www.jurjans.lv/stuff/net/FreeNet.htm. It's all pretty straightforward stuff, but I'm mentally stuck on how to generate the initial network.
I could do it square by square with lots of if/else logic checking neighboring squares, but frankly it seems very laborious and I wonder if there's a much much MUCH smarter way. Generate a mathematical graph or something similar and then translate that into the grid?
I'm not asking for someone to code it all for me - just point me in the right direction!
The completed circuit appears to be a spanning tree.
There is an easy way to generate random minimum spanning trees by:
assigning random weights from some distribution to the edges of an undirected graph, and then constructing the minimum spanning tree of the graph.
So to summarise:
Build a graph with a vertex at the centre of each square
Add edges between each vertex and its neighbours above/down/left/right
Assign random weights (e.g. uniform real from 0 to 1) to each edge
Construct minimum spanning tree e.g. with Prim or Kruskal
Convert graph into tiles
If there are certain shapes you want to forbid (e.g. a fully connected vertex) you may want an extra iteration to increase the weight for edges used in any tiles that are illegal, and then regenerate the spanning tree until you end up with a legal graph.

Optimal algorithm to check which vertices in a set of polygons can be connected to a point without overlap

I have a set of polygons described by their vertices. My question is, given a certain vertex, how can I find the vertices of all the polygons to which I can draw a line segment from the given vertex without overlapping the polygons.
Is it possible to do in less than O(n^2)?

How to find the 'outline' of a (concave) graph in 2D plane?

I have a connected graph in 2D plane composed of some vertices and some edges defined between them. The overall shape of the graph is not necessarily convex, i.e. the adjacent vertices on the convex hull are not always connected by an edge. Now is there an existing algorithm that finds the 'outline' of this graph? The issue that's troubling me the most is that this outline polygon may contain vertices that are not vertices in the original graph, but rather the intersection of two edges, so I'm not quite sure how to deal with it...
Thanks!
Niko

An algorithm to draw graphs without checking all pairs of vertices?

Graph drawing algorithms, such as those described here, check all the vertices two-by-two and apply additional forces if two vertices are connected by an edge. If we have a very large graph, checking all pairs of vertices would be costly. Is there any graph drawing algorithm that draws a large graph using only existing edges, not by verifying all possible pairs?
EDIT
By drawing algorithm, I meant an algorithm that assigns a 2D or 3D position to each vertex such that rendering spheres or circles (or any other shape) as vertices at their assigned positions lead to a plausible visual representation of the whole graph.
Check this Spring-Electrical Embedding
It is in O(nlog n).
If you have sparse matrix you can consider about creating graph as list of neighbours or simplier like pair of vertices (e.g. (1, 3) and 1 and 3 are the numbers of vertices).

Efficient Way to construct triangles from Edges/Lines?

Lets say I have a set of points and I have lines/edges between them. All of these edges create non-overlapping triangles within the convex hull of my points. All points are connected to triangles.
How can I efficiently check which points are part of which triangle? I could check incident points of each edge and gradually construct a triple of points, but that sounds awefully slow (o(n^2)?).
Is there something like linesweep or so to do that?
cheers.
If you have a 2-dimensional set-up like you described, then you have a fully triangulated planar graph (no intersecting edges when you exclude the endpoints) which spans the convex hull of your points. In this case, if you sort the edges around each vertex circularly according to the angle they make with the vertex, then you know for sure that each pair of adjacent edges makes a triangle. Furthermore, every triangle can be found this way if you perform this procedure for each vertex. Each triangle will be found 3 times when you iterate over all vertices. You can either use a hash table to detect duplicates, or sort all your triangles when you are done to identify duplicates. If you use hash table, then the overall complexity if you have V vertices is O(V log d), where d is the maximum degree of a vertex (because the total number of edges is linear in the number of vertices because you have a planar graph). So absolute worst-case is O(V log V), which is the same worst-case if you sort all triangles to find duplicates (because the max number of triangles is also linear in the number of vertices). The only caveat to make this work is that you need to know the neighbor vertices (i.e. the incidental edges) for each vertex.
The edges define an undirected graph G and the triangles are the set of cycles in G with length=3.
Geometric triangulations typically have relatively low nodal degree (degree d is the number of edges adjacent to each node, d<=10 is typical for geometric triangulations) and, as such, here is a reasonably efficient O(n*d^3) algorithm that can be used to construct the set of triangles.
Setup a graph-like data structure, supporting access to the list of edges adjacent to each node.
Iterate over all nodes. Consider all pairs of edges adjacent to a given node i. For a given pair of edges adjacent to i, we have a potential nodal triplet i,j,k. This triplet is a triangle if there is an edge joining nodes j,k, which can be checked by scanning the edge lists of j,k.
Duplicate triangles will be generated by a naive implementation of (2). Maintain a hash table of triangles to reject duplicate triplets as they're considered.
I've assumed that the edges define a valid disjoint triangulation, being non-intersecting, etc.
Hope this helps.

Resources