I'm building a video game in which a 2D planar graph is constructed edge by edge, and the faces of the graph need to be known at any given point. By "faces", I mean cycles of the graph that do not have any edges cutting through them on the 2D plane.
I'm aware of cycle basis and have implemented it with excellent results, but I was wondering whether there were algorithms/data structures that maintained an invariant while building a set of faces incrementally while the graph was also being built.
For reference, here is a video I found on YouTube.
I wish to understand how/if this is possible to do with minimal computation at every addition of one edge to the graph. I've also tried looking at half-edge and winged edge implementations of a 2D planar graph, but I have found nothing so far that gives me insight into this. Thanks a lot!
Related
I am looking for an algorithm to find all (or maximum no of) contiguous faces of a continuous mesh. The faces should be ordered in an array in such a way that each face is preceded by a face linked to it on the mesh. The ultimate goal is to have a single such array. Is it possible even in theory? If not what's the best way to maximize the count of faces in the array?
In this (rather naive) implementation the selection point traverses clockwise covering end vertex of the available edge of the last face covered. But this quickly gets into a dead-end. I also tried both the ends of the edge, or all the available vertices of the face, but sooner or later each one reaches a face with no connections to un-selected faces.
Edit:
It's a triangulated mesh, i.e. each face has exactly three vertices. And the requirement is to have a set of minimum no of arrays (ideally one) covering all the connected faces of the mesh.
This is a hard problem (the Hamiltonian path problem in a planar graph (specifically, the dual of the input graph)), but you may have get good results with a local search method. There's a simple one due to Angluin and Valiant (https://doi.org/10.1016/0022-0000(79)90045-X) and a more complicated effort by Frieze (https://doi.org/10.1002/rsa.20542). These algorithms are proved in theory to work on random graphs only, but graphs without adversarial construction are often amenable too.
I have a graph where nodes represent points in 3D space. Each node is connected only to all other nodes within some cutoff radius. I am trying to enumerate all subgraphs such that the nodes represent the vertices of a polyhedron with no interior nodes or edges.
At first I thought this was clique problem, but the requirement that all nodes are adjacent to each other isn't working for me. The opposite corners of a cube aren't going to be connected in my dataset, but I need to be able to pull out the cube.
I don't really have a formal education in CS, so I'm not really sure what to search for, but hopefully someone with a better domain vocabulary than me can point me in the right direction.
One way to attack this problem seem to me to use a 3D triangulation "tetrahedrisation". CGAL can be of service there. Then you can start generating different polyhedrons by sticking together neighboring tetrahedrons from the triangulation (as long as they don't inclose another vertex in their combined interior).
Are there any algorithms to minimize edge crossings in a graph? For example if I have a transition matrix of the graph.
I found methods like trying to place the nodes around the other node, but I'd like to know some other ideas.
There's a range of well established algorithms/libraries that have been developed for graph drawing applications, you can get a bit of background here.
To draw undirected graphs a popular choice is the force-based layout algorithm, in which graph edges are treated as springs (attractive forces) while the vertices are treated like charged particles (applying repulsive forces). The algorithm works by updating the vertex positions based on these forces until a steady-state is reached. You can read more about force based methods here. Since these algorithms search for an equilibrium solution they often result in pseudo-optimal layouts, without much edge tangling.
You might be interested in making use of one of the many graph drawing libraries that are available. The Graphviz package is generally pretty good and supports a number of different algorithms for different graph drawing applications.
I'm dealing with a graph with n nodes' coordinate and m undirected edges, how can I get a better visual graph(with less crossing) by allow using some broken line instead of straight line?
I know minimize the crossing number is a NP problem. So I just ask for some help here beacuse I think someone may give me some resources about it.
What's more, I think it is ok that change some nodes' coordinate(not move them too far), all in all, it's the problem that how to find a more clear graph for our eyes!
GraphViz website is a good place to start learning about graph visualization.
The Boost graph library (i.e. BGL) has plenty of algorithms and data structures to experiment with, and a dual interface (c++ of course, or python). Of course, Boost isn't the easiest way to start. Surely Graphviz (that BGL can interface) it's way simpler.
In the BGL docs there are many resource you could find useful: for instance, from the previous link:
Any plane drawing separates the plane into distinct regions bordered by graph edges called faces. As a simple example, any embedding of a triangle into the plane separates it into two faces: the region inside the triangle and the (unbounded) region outside the triangle. The unbounded region outside the graph's embedding is called the outer face. Every embedding yields one outer face and zero or more inner faces. A famous result called Euler's formula states that for any planar graph with n vertices, e edges, f faces, and c connected components,
n + f = e + c + 1
This formula implies that any planar graph with no self-loops or parallel edges has at most 3n - 6 edges and 2n- 4 faces. Because of these bounds, algorithms on planar graphs can run in time O(n) or space O(n) on an n vertex graph even if they have to traverse all edges or faces of the graph.
A convenient way to separate the actual planarity test from algorithms that accept a planar graph as input is through an intermediate structure called a planar embedding. Instead of specifying the absolute positions of the vertices and edges in the plane as a plane drawing would, a planar embedding specifies their positions relative to one another. A planar embedding consists of a sequence, for each vertex in the graph, of all of the edges incident on that vertex in the order in which they are to be drawn around that vertex. The orderings defined by this sequence can either represent a clockwise or counter-clockwise iteration through the neighbors of each vertex, but the orientation must be consistent across the entire embedding.
In the Boost Graph Library, a planar embedding is a model of the PlanarEmbedding concept. A type that models PlanarEmbedding can be passed into the planarity test and populated if the input graph is planar. All other "back end" planar graph algorithms accept this populated PlanarEmbedding as an input. '
I want to generate random points in a 2D space, this points will be nodes of a planar graph (built using Gabriel graph algorithm or RNG ).
I wrote java code to do this, but I have two hard problem to solve.
1) I need that all edges of the graph are not longer than a given threshold
2) After I want know faces of graph, a face is a collection of nodes connected by edge. A face does not contain within it other nodes. In image below faces are signed by label (F1, F2...)
How to do these two thing ? some algorithms ? There is some way already known?
Below there is an example of the graph that I must to create
http://imageshack.us/photo/my-images/688/immagineps.png/
If you can tolerate some variance in the number of points, then you could modify your Gabriel graph algorithm to be incremental (most of the effort would be making your Delaunay algorithm incremental) and then whenever an edge is too long, insert a random point in the circle having that edge as a diameter.
The most convenient data structures for plane graphs are edge-centric: for example, the doubly-connected edge list and the quad-edge representations. If you're not already using a data structure of this type for the Delaunay step (and I can't imagine why you wouldn't be), you can sort each vertex's outgoing connections by angle. From there, it's easy to implement a function that takes a half-edge and returns the next half-edge on the same face in counterclockwise order. Now iterate through all of the half-edges, and for each half-edge not already visited, iterate around the face until you return to where you started. Label all of the half-edges in the inner iteration as one face.