Finding Faces in a Geometric Directed Graph - graph

I'm confronted with a rather unusual problem dealing with an directed geometric graph. Imagine the graph being borders of countries. I'm looking for a way to find the faces. My graph consists of directed edges which may form cycles (but not necessarily).
What I am looking for are the left and right faces as well as the predecessors and successors of the left and right faces for each edge.
Each face should be constructed anti-clockwise, meaning that the left face of an edge is always inside and the right face is outside of the specific face.
At the end of the day the nodes of the faces are geographic coordinates (lat and lon).
This is the information I am looking for (beginning from LeftFace..)
+------+-------+-------+----------+-----------+---------------------+--------------------+
| Edge | NodeA | NodeB | LeftFace | RightFace | PredecessorLeftFace | SuccessorRightFace |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E1 | P1 | P2 | A | C | E5 | E2 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E2 | P2 | P3 | A | C | E1 | E6 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E3 | P3 | P4 | A | B | E2 | E8 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E4 | P4 | P5 | A | C | E3 | E5 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E5 | P5 | P1 | A | C | E4 | E1 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E6 | P3 | P6 | B | C | E3 | E7 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E7 | P6 | P7 | B | C | E6 | E8 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E8 | P7 | P4 | B | C | E7 | E4 |
+------+-------+-------+----------+-----------+---------------------+--------------------+

For each directed edge add also opposite edge in a graph. Than, for each (directed) edge find face in that direction. That means, traverse face edges so that in every vertex choose leftmost neighboring edge, until path returns to starting vertex. To choose leftmost edge, 2D positions of vertices are needed.
Example of choosing leftmost edge: going from P3 to P4 (opposite of E3). In P4 there are two possibilities to continue path, P5 and P7. Now check angles on the left side of edges. P3-P4-P5 is ~90deg, and P3-P4-P7 is ~270deg. Angle P3-P4-P5 is smaller than P3-P4-P7, so next edge in path is E4, and next point in path is P5.
Algorithm:
For each directed edge add opposite edge
While there are edges in graph
Choose one directed edge
Find edges that enclose face (on left side) starting from that edge
Add face to list of faces
Remove face edges from graph

Related

Suggested Tools for Visualizing a Subgraph DAG

I am writing a program which basically processes a subgraph DAG, i.e., the graph is a directed acyclic graph and each node of the graph is a subgraph. For example, for an edge A->B in the DAG, node A is a subgraph of a triangle and node B is a subgraph of a four clique. The edge A->B indicates an extension from a triangle to a four clique by adding one subgraph vertex and three subgraph edges.
+=======+ +=======+
| a---b | | a---b |
| | / | | |\ /| |
| | / | =====> | | X | |
| |/ | | |/ \| |
| c | | c---d |
+=======+ +=======+
A B
For many purposes, I want to visualize this subgraph DAG, i.e., the visualization can show the entire structure of the DAG and show the subgraph of all the nodes at the same time. Also it would be better if it can also show properties of vertices and edges.
I am able to list all the nodes and edges of the DAG and the subgraphs of all the nodes in any format. But what I don't know is what tool is the best for such visualization. I tried graphviz by exporting the subgraph DAG into dot format and use graphviz to convert the dot file to a png. The problem of graphviz is it can show the subgraph of nodes very well but it fails to show the structure of the DAG in a human-readable way. It would be good if
for a DAG edge A->B, node A is placed above node B. (graphviz now puts all the DAG nodes in the same row)
the nodes are placed properly such that the intersection among the DAG edges is minimized.
Are there any other alternatives? Thanks in advance!
If I understand your requirements, I think this dot program comes pretty close:
digraph dag {
compound=true // needed for A->B edge (kludge, but documented)
edge [dir=none] // no arrowheads
subgraph clusterA{
labelloc=b
label="A"
Aa -> Ab // [constraint=false] // keep on same rank
Ab -> Ac
Aa -> Ac
{
rank=same
Aa [label="a"]
Ab [label="b"]
}
Ac [label="c"]
}
subgraph clusterB{
labelloc=b
label="B"
Ba -> Bb // [constraint=false] // keep on same rank
Bc -> Bd // [constraint=false] // keep on same rank
Bb -> Bc
Ba -> Bc
Bb -> Bd
Ba -> Bd
{
rank=same
Ba [label="a"]
Bb [label="b"]
}
{
rank=same
Bc [label="c"]
Bd [label="d"]
}
}
Ac -> Ba [dir=forward ltail=clusterA lhead=clusterB minlen=2]
}
Here is the output:

3D rotation matrix (rotate to another reference system)

Is there a direct approach to construct a rotation matrix from the following input?
Say there is a standard perpendicular reference: X[1,0,0], Y[0,1,0], Z[0,0,1] and I want rotation matrix to rotate it to match another perpendicular reference X'[a1,b1,c1], Y'[a2,b2,c2], Z'[a3,b3,c3]. Vectors are unit vectors.
Is it possible that the matrix would be like below?
a1, a2, a3
b1, b2, b3
c1, c2, c3
Given points defined in a XYZ coordinate system, you transform them to a X'Y'Z coordinate system with a 3x3 rotation matrix. In general, the components of the local a, b, and c axes arranged in columns in the world coordinates represent the local->world transformation for that system such that
| x_world | | a1 b1 c1 | | x_local |
| y_world | = | a2 b2 c2 | | y_local |
| z_world | | a3 b3 c3 | | z_local |
and the reverse transformation (with a matrix transpose)
| x_local | | a1 a2 a3 | | x_world |
| y_local | = | b1 b2 b3 | | y_world |
| z_local | | c1 c2 c3 | | z_world |
Now to transform between any two coordinate systems with local->world rotation matrices XYZ and X'Y'Z' (note in your case XYZ is the 3x3 identity matrix) you chain the above for
point_x'y'z' = transpose(X'Y'Z') * (XYZ) * point_xyz
| x' | | a1 b1 c1 | | x | | a1 x + b1 y + c1 z |
| y' | = | a2 b2 c2 | | y | = | a2 x + b2 y + c2 z |
| z' | | a3 b3 c3 | | z | | a3 x + b3 y + c3 z |
Yes, the transformation from identity to any other transform is the other transform. Usually you do not call these things rotation matrices because they represent any arbitrary transformation. It may be that the transformation may not be achievable by rotation alone, as the transformation may be mirrored about one or two planes.
Please note while your using column vector's it is perfectly possible to also use row vectors in which case your results are just transposed, and multiplication order the reverse. Mathematically its the same thing. So check your system

Drupal business listing a-z indexing requirements

I want to render something like below in a view.
==================================================================
View: Car parts (Content type)
A | [B] | C | D | E | [F] | [G] | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
BONNET
FRONT BUMPER
FRONT BAR REINFORCEMENT
GUARD LEFT
GUARD RIGHT
==================================================================
How do you create the top A – Z index. The letters in [ ] are anchor links.
I think this discussion could help you:
https://drupal.org/node/403012

Removing Left Recursion from CFG

The following grammar has left recursion:
T -> Tx | TYx | YX | x
X -> xx
Y -> Yy | Yx | y
How do you go about removing left recursion. I read the wikipedia explanation, but I'm fairly new to CFGs so it did not make a lot of sense. Any help is appreciated? A plain english explanation would be even more appreciated.
In this example, you can follow Robert C. Moore's general algorithm to convert a rule with left recursion to a rule with right recursion:
A -> A a1 | A a2 | ... | b1 | b2 | ...
# converts to
A -> b1 A' | b2 A' | ...
A' -> e | a1 A' | a2 A' | ... # where e = epsilon
In our first case: A=T, a1=x, a2=Yx, b1=y, b2=x... (similarly for Y)
T -> YXT' | xT'
T' -> e | xT' | YxT'
X -> xx
Y -> yY'
Y' -> e | yY' | xY'

R: graphing upper and lower bounds with ggplot2

I have a dataset with three variables. One continous independent variable, one continous dependent variable, and a binary variable that catagorizes how the measurements were taken. Using ggplot, I know that I can make a scatter plot with the points colored by the catagory:
g <- ggplot(dataset, aes(independent, dependent))
g + geom_point(aes(color=catagory))
However, I want to know if there is a way to make a graph where there is a vertical line comming up from points of catagory 0 and a vertical line going down from points of catagory 1. It would look something like this:
- | | |
| | | |
| | | |
| | | |
- | | o |
| | | | |
| | o | | |
| | o | | | |
- | | | o | o
| | | | |
| o | | |
| | | |
+----|-----|-----|-----|-----|
The reason for wanting a plot like this is that one category represents an upper bound (the points with lines going downwards) and one represents a lower bound (the points with lines going upwards). Having these lines would make it easy to visualize the area which is between these bounds, and whether a function plotted on top could accurately represent the data:
- | | |
| | | |
| | | |
| | | |
- | | o | _____
| | | |_|__/
| | o |_/| |
| | o |__/| | |
- | | /| o | o
| _|_|/ | |
| / o | | |
|/ | | |
+----|-----|-----|-----|-----|
If there is any way to do this using ggplot or any other graphing library for R, I would love to know how. However, if it isn't possible, I'd be open to hearing other ways to represent this data. Simply distinguishing the catagories based on color doesn't do enough to emphasize the upper/lower bound nature of the catagories for my purposes.
The following could work for you, I hope I understood the problem well.
First, generating some random data for the dataframe, as no sample data was provided. The random numbers will make the plot ugly, I hope it will look better with real data:
dataset <- data.frame (
independent = runif(100),
dependent = runif(100),
catagory = floor(runif(100)*2))
Next, find the upper or lower part of the plot (=min/max of values) based on "catagory" for every case:
dataset$end[which(dataset$catagory == 0)] <- max(dataset$dependent)
dataset$end[which(dataset$catagory == 1)] <- min(dataset$dependent)
Now, we can plot data with geom_segment().
g <- ggplot(dataset, aes(independent, dependent, min, max))
g + geom_segment(aes(x=independent, y=dependent, xend=independent, yend=end, color=catagory))
Note, that I also added + theme_bw() + opts(legend.position = "none") parameters to the plot as it looked very strange with random datas.

Resources