• Keine Ergebnisse gefunden

Polyline Representation

Im Dokument Constrained Graph Drawing (Seite 48-60)

Angles and Distances

3.3 Angle and Distance Constraints

3.3.2 Polyline Representation

If an angle and distance constrained tree is not straight-line realizable, it can still be drawn without edge intersections by allowing polylines. In the remainder of the section, we will prove the following theorem.

Theorem 7. For a tree, a planar polyline drawing that satisfies locally consis-tent angle and distance constraints and has at most two bends per edge can be determined in linear time.

In the first step we calculate an initial layout ofTrfor an arbitrary rootr∈V with the length-preserving Algorithm 2 and given edge lengthsδ. The algorithm assigns a wedge of sizeω(v) to each vertexv ∈V that contains the whole subtree Tr(v) ofv and is then divided among the children. With these vertex positions, we look at the unrooted tree T and all the wedges of v’s neighbors are rooted in v. The vertex w0, which had been v’s parent in Tr, is now lying in an opposed wedge with size ω(w0) = 2π −ω(v) (see Fig. 3.14). We exploit this invariant characteristic of the computed layouts:

Theorem 8. For a tree with given vertex positions, a planar polyline drawing that satisfies locally consistent angle constraints and has at most two bends per edge can be determined in linear time, if the given vertex positions are such that disjoint subtrees are contained in disjoint wedges.

Figure 3.14: Wedges for vertexv

This is a special case of the problem to find a drawing of a planar graph with fixed vertices and pre-specified angles between the edges incident to the same vertex (Brandes, Shubina, and Tamassia, 2000). A related problem is embedding a planar graph on a fixed set of points in the plane. The graph can be drawn without edge intersections using at most two bends per edge in polynomial time, if the mapping between the vertices V and the pointsP is not fixed (Kaufmann and Wiese, 2002). However, if the mapping is fixed, i. e., each vertex has a fixed position such that the straight-line drawing is not necessarily planar, up toO(n) bends per edge can be necessary to guarantee planarity and this bound is known to be asymptotically optimal in the worst case (Pach and Wenger, 1998). Note that these strategies do not yield drawings that satisfy angle constraints. Angle constraints have to be satisfied for example when drawing graphs with good angular resolution. A planar graph can be embedded and drawn planar with at most one bend per edge such that for each (e1, e2)∈Asharing a vertex v ∈V it is α(e1, e2) ≥ deg(v)1 (Cheng, Duncan, Goodrich, and Kobourov, 1999). For not necessarily planar graphs, angular resolution and the number of edge crossings can be improved by modifying a force-directed graph drawing algorithm into an algorithm for drawing graphs with curved edges (Finkel and Tamassia, 2005).

Note that for these drawings no distance constraints are to be satisfied.

Figure 3.15: Polylines for the edge{v, w}

In our drawings, edges will be represented as polylines. The polyline of an edge{v, w}will be determined by the endpoints of twocontrol segments incident tov and w (see Fig. 3.15).

We guarantee the planarity in two steps: For a vertex v ∈V

• we determine the direction of each initial control segment.

• we determine the length for each initial control segment.

In Sect. 3.3.2.1 we define a rotation angle β to guarantee certain situations regarding the angles of the initial control segments incident to a vertex v and those of the straight lines fromv to the corresponding neighbors. In Sect. 3.3.2.2 we determine the control segment lengths to avoid intersections in the remaining situations.

Figure 3.16: Rotating the angle template

We will focus on each vertex a constant number of times and look at all incident edges such that the overall run time is linear.

Let v ∈ V be a vertex with k incident control segments s0. . . sk−1 (in coun-terclockwise order) belonging to the k polylines of edges e0. . . ek−1 to the k neighbors w0. . . wk−1 of v. We refer to the absolute angle of a control segment si withγi0+Pi

t=0α(et−1, et) andli its length. Further, let s0i be the control segment forei incident towi with angleγi0 and lengthl0i. Letpidenote the target point of si and p0i the target point of s0i, λi the absolute angle of the line from v towi and λ0i the angle of the same line, but from wi tov.

Figure 3.17: Routingearoundv

3.3.2.1 Control Segment Angles

Since only the relative angles between consecutive control segments incident to v are given, to determine the final layout we must choose the absolute angle for one of the control segments. We start with γ0 = λ0 and then rotate the whole angle template by an angleβ, i. e., update each angle γii±β (see Fig. 3.16).

For a neighbor wi of v, the angular deviation is θ(i) = (γi−λi) mod 2π. We say thatwj lies between si andwiif (γi−λj) mod 2π <(γi−λi) mod 2π, whereas a control segmentsj lies betweensi andwiif (γi−γj) mod 2π <(γi−λi) mod 2π.

In Fig. 3.18(a) for example,s0andw0 lie betweensi andwi. We assume that the endpointp0i of the control segments0i and the neighborwi which s0i is incident to, lie on the same side of the line (v, pi) such that the polyline of ei can only cross the wedge of a neighborwj with either pi itself withinwj’s wedge or wj between si andwi for θ(i)< π andwj betweenwi and si forθ(i)> π (see Fig. 3.17). We will assure this when determining the control segment lengths (see (3.23)).

The following two situations will cause intersections in the starting configu-ration becauseei will be intersecting with e0 (see Fig. 3.18 for illustration). For a pair si, wi we say that

i and 0 are clockwise crossing if

θ(i)≤π and w0,s0 lie between si and wi, (3.18)

i and 0 are counterclockwise crossing if

θ(i)≥π and w0,s0 lie between wi and si. (3.19)

(a) clockwise crossing (b) counterclockwise crossing Figure 3.18: Two cases in the start situation

Lemma 4. At any vertex v ∈ V there are either clockwise or counterclockwise crossings, if any.

Proof. Assume i1 fulfills Equation (3.18) and i2 Equation (3.19), then s0 lies between si1 and si2 and w0 lies between wi2 and wi1. The orders of the control segments and of the neighbors are fixed, hence i1 < i2 and i1 > i2, which is a contradiction.

If a vertex v has a neighbor wi such that i and 0 are clockwise crossing, we rotate v’s angle template counterclockwise. If i and 0 are counterclockwise crossing for an 0 ≤ i ≤ k −1, this is the mirrored case and can be solved by rotating clockwise.

Assume w.l.o.g. that there are only clockwise crossings atv. Out of all pairs {si, wi}for whichiand 0 are clockwise crossing, letimin be the one for which the angular deviation θ(i) is minimal and of all pairs {si, wi} for which i and 0 are not clockwise crossing butθ(i)< πletimaxbe the one for whichθ(i) is maximal.

We rotate the angle template counterclockwise by an angle β with

0≤π−θ(imin)< β < π−θ(imax)≤π (3.20) Lemma 5. For every vertex v there is a feasible rotation β, i. e. θ(imin) >

θ(imax).

Proof. For imax > imin, the vertex wimax lies between w0 and wimin because the order of neighbors is fixed. It is θ(imax) < π but imax and 0 are not clockwise crossing, hence simax lies between w0 and wimax. So it must be θ(imin)> θ(imax) because both simax and wimax lie between simin and wimin. The proof for the case imax> imin is analogous, as for imin> imax simax lies between simin and s0.

Lemma 6. These bounds are sharp.

Proof. For β ≤ π − θ(imin) it would still be that θ(imin) ≤ π after rotation and both w0 and s0 would still lie between simin and wimin, hence eimin would be intersecting with e0.

Forβ ≥π−θ(imax) it would be true thatθ(imax)≥π after rotation and both wimin andsimin would lie betweenwimax andsimax, henceeimin would be intersecting with eimax.

Within these bounds we can now optimize any objective function, for example the sum over all squared angular deviationsθ(i)2 for 0≤i≤k−1. See Brandes, Shubina, and Tamassia (2000) for other reasonable objective functions.

After rotating the angle template we will have (see Fig. 3.19):

Lemma 7 (counterclockwise sheering). For 0≤i, j ≤k−1, wj lies between wi

and si with angular deviation θ(i)> π, if and only if si also lies between wj and sj with θ(j)> π.

Lemma 8 (clockwise sheering). For 0≤i, j ≤k−1, wj lies between si and wi

with angular deviationθ(i)< π, if and only if si also lies betweensj and wj with θ(j)< π.

In these two situations we can avoid intersections by determining the control segment lengths in Sect. 3.3.2.2.

We say si is pulled between sj and wj if it was (λj −γi) mod 2π < π before rotation, but is (λj −γi) mod 2π > π after rotation and si lies between sj and wj. We say si is pushed over wj if it was (λj−γi) mod 2π < π before rotation, but is (λj−γi) mod 2π > π and wj lies between si and wi after rotation.

To prove Lemma 7 and Lemma 8, we first prove the following:

(a) counterclockwise sheering (b) clockwise sheering Figure 3.19: Two solvable situations

Lemma 9. If θ(i)> π after rotation for 0≤i≤k−1, before and after rotation neither w0 nor s0 can lie between wi and si.

Proof. Ifθ(i)> π before rotation,w0 and s0 cannot have lain betweenwi and si

because i and 0 would have been counterclockwise crossing. We rotate counter-clockwise by an angle β < π keeping θ(i)> π, hence they cannot after rotation as well.

If θ(i) ≤ π before rotation but θ(i) > π after, i and 0 must have been clockwise crossing before rotation, hencew0 and s0 cannot lie betweenwi and si

after rotation.

Lemma 10. If θ(i)< π after rotation for 0≤i≤k−1, w0 and s0 cannot both lie between si and wi.

Proof. Before rotation, i and 0 cannot have been clockwise crossing. So by rotating counterclockwise by an angleβ < π from the start situation λ00, it can only happen that either si is pushed over w0 or s0 is pulled betweensi and wi.

Lemma 11. For any i with 0≤i≤k−1, wi and si cannot both lie between s0

and w0.

Proof. It is θ(0) = β < π. Assume both wi and si lie between s0 and w0. For θ(i)< π,iand 0 would have been counterclockwise crossing before rotation. For θ(i) > π, both w0 and s0 would have lain between wi and si before rotation, which is contradicted by Lemma 9.

Corollary 2. For the angular deviation of a vertex wi, it is impossible that θ(i) = π after rotation for any 0≤i≤k−1.

Proof. of Lemma 7

If wj lies between wi and si with θ(i)> π, neither s0 nor w0 can lie between wi and si (Lemma 9), so w0 cannot lie between wi and wj and we have j < i.

Because the order of control segments is fixed, s0 cannot lie between si and sj, hence s0 must lie between sj and wi and s0 lies between sj and wj. If it is θ(j)< π, s0 must have been pulled between sj and wj (Lemma 10) so s0 must have lain betweenwi and si, which is a contradiction to Lemma 9.

If si lies between wj and sj with θ(j)> π, neither s0 nor w0 can lie between wj and sj (Lemma 9) so s0 cannot lie between si and sj and we have j < i.

Because the order of neighbors is fixed,w0 cannot lie betweenwi and wj, hence w0 must lie between sj and wi and w0 lies between si and wi. If it is θ(i)< π, si must have pushed overw0 (Lemma 10), so sj must have also pushed overw0, hencew0must have lain betweenwj andsj, which is a contradiction to Lemma 9.

Proof. of Lemma 8

If wj lies between si and wi, wi cannot be between wj and sj with θ(j)> π (Lemma 7). For j < i, w0 lies between wj and wi. w0 can not lie between wj

and sj (Lemma 9, thus sj can not lie between w0 and wi. s0 cannot lie between si and wi (Lemma 10) and asθ(0) =β < π,si lies between s0 and w0. Further, s0 must lie between sj and si because the order of control segments is fixed. sj

cannot lie between s0 and w0 (Lemma 11), thus we have si lies between sj and wj with θ(j)< π after rotation. Fori < j, s0 must lie betweensi andsj. wi can not lie between sj and s0 (Lemma 9). If sj lies between si and wi, s0 must lie betweensi and wj (Lemma 9 excludes s0 betweenwj andsj), while w0 lies with θ(0) =β < π. Again, sj cannot lie between s0 and w0 (Lemma 11), thus si lies between sj and wj with θ(j)< π after rotation.

If si lies between sj and wj, sj cannot be between wi and si with θ(i) > π (Lemma 7). For j < i, s0 lies between sj and si. w0 cannot lie between sj and wj (Lemma 10) and it must be θ(0) =β < π. wi can not lie betweens0 and wj

(Lemma 11), hence wj lies between si and wi with θ(i)< π after rotation. For i < j, w0 must lie between wi and wj because the order of control segments is fixed. Ifwiwas betweensj andwj,w0must lie betweensi andwj (Lemma 9). s0

cannot lie between sj and wj as well (Lemma 10), hence, both wi and si would lie betweens0 and w0 (contradicted by Lemma 11). Thuswj lies betweensi and wi with θ(i)< π after rotation.

3.3.2.2 Control Segment Lengths

In the remaining situations we can avoid intersections by determining the lengths of an edge’s control segments. First we focus on edges ei = {v, wi} incident to

a vertexv and make sure that they do not intersect with each other (at a point different from v itself).

We assure that the polyline of ei can only cross the wedge of a neighbor wj

with either wj between si and wi for θ(i) < π and wj between wi and si for θ(i)> π, or pi itself within wj’s wedge.

We further determine the radius rv of the circle containing all control seg-ments incident to a vertexv such that:

• control segments incident to different neighbors ofv can not intersect

• the control segments incident tov can not intersect with a control segment incident to any ofv’s neighbors

For an edgee ={v, w}, the maximal possible length l of e’s control segment s incident to v is determined such that:

• neither the middle segment of e nor the control segment s can intersect with a control segment incident to another neighbor

• neither the middle segment of e nor the control segment s can intersect with the middle segment of another edge

With these control segment lengths we can draw the polylines incident to v neither intersecting each other nor with any polyline in T. We will show the latter when proving that curves incident tov are not intersecting with any other curve in T (Lemma 13) as the polyline of an edge is the border of the hull containing the edge’ s curve.

The polyline of ei incident to v can only cross the wedge of a neighbor wj

withwj betweensi and wi forθ(i)< π and wj betweenwi and si forθ(i)> π pi

if wi and the endpoint p0i of ei’s control segment incident to wi lie on the same side of the line (v, pi). We assure this by choosing the length l0i of s0i such that s0i does not intersect with the line (v, pi). If the halfline from wi through p0i does not intersect with (v, pi), the length of s0i is not relevant. Otherwise we use the following:

If (γi0−λ0i) mod 2π > π (see Fig. 3.20):

The angle between (v, pi) and (v, wi) is η=

((γi−λi) mod 2π if θ(i)< π

(π−λii) mod 2π otherwise (3.21) Further we use the angle κ with:

κ= π

2 −η−λii (3.22)

Figure 3.20: i0λ0i) mod 2π > π andθ(i)> π

Since sin(η+π) =−sin(η) and cos(κ) = sin(κ+ π2), we summarize:

l0i < sin(γi+π−λi)·δ(ei)

sin(−γii−λ0ii0) (3.23) Since for (γi0−λ0i) mod 2π < π we get:

l0i < sin(λi−γi−π)·δ(ei)

sin(−λii−γi00i) (3.24) we do not even have to distinguish (γi0−λ0i) mod 2π > π and (γi0−λ0i) mod 2π < π but instead only need (3.23).

Let wi be one neighbor of v. We call the (smallest) sector of wi’s wedge, in which the control segments0i incident to wi is lying, the range of wi. If another control segmentsj incident tov is lying within this range, the polylines ofei and ej can be intersecting without i and j clockwise or counterclockwise sheering.

We avoid this by choosing the lengthli0 ofs0i such thats0i is not intersecting with the line (v, pj) for anyj 6=i(see Fig. 3.21). The computation is analog to (3.23).

To guarantee that the control segments incident to one neighbor are not intersecting with the control segments of another neighbor, we determine for 0≤i≤k−1:

rwi <

(sinωwi2 · kwi−v k2 if ωwi < π

sin(π− ω2wi)· kwi−v k2 otherwise (3.25)

Figure 3.21: Range ofwi

We must also guarantee that the control segments incident to v are not intersecting with the control segments incident to one of v’s neighbors:

rv ≤ 1

2min{δ(ei)}0≤i≤k−1 (3.26)

We first compute (3.25) for each vertex v ∈V and then (3.26) to determine rv, which we will need in the following.

A neighbor wi cannot be involved both in a clockwise and a counterclockwise sheering. Let i and (i+ 1) modk (we will write i+ 1 in the remainder) be counterclockwise sheering. We have to further determine the length li+1 of the control segment si+1.

The polyline of an edgeei+1might intersect witheior another edge incident to wi if a line throughp0i+1andpi+1would be intersecting with the circle containing all control segments incident towi. We can avoid this by choosingli+1 such that si+1 is not intersecting with any tangent line towi’s circle throughp0i+1. Further, si+1 must not intersect with the line gi = (pi, p0i). As we might not know the final lengths of s0i+1 and s0i we use that 0 < l0i+1 ≤ rwi+1 and 0 < l0i ≤ rwi. See Figure 3.22(a) for illustration.

The computations for a length li+1 such that si+1 is not intersecting with one of these lines are all very similar. We show the computation here for a line g where φi is the angle between g and si in (3.27) (see Figure 3.22(b) for illustration):

li+1 < sinφi·li

sin(π−φi−α(ei, ei+1)) (3.27)

(a) lines (b) length of si+1

Figure 3.22: Bounding control segments

Note that not only i+ 1 and i can be counterclockwise sheering but also i+ 1 and j for any j < i. As from this, i+ 1 and any j0 with i < j0 < j are counterclockwise sheering and since we have consideredj0 beforei, it is sufficient to focus on i when determiningli+1.

These procedures imply thatlimust be calculated first. Therefore we create a vertex listL+containingv0s neighbors sorted by increasing index andθ(i)< πfor eachwi ∈L+. If forv there is a pairiand (i−1) modk clockwise sheering, this is symmetrically the same situation and will be solved with the same strategy.

We will need a vertex list L sorted by decreasing index and θ(i) > π for each wi ∈L. We can create both types of vertex lists by testing all neighborswi for 0≤ i ≤k−1 in counterclockwise order. There must be a neighbor wi to start with, i. e., such thatli−1 does not have to be calculated first. We prove:

Lemma 12. Neither the vertex list L+ nor L will contain all neighbors of v. Proof. We start with the angular deviationθ(0) = 0. If we do not have to rotate v’s angle template, the neighbor w0 will be in none of the vertex lists. If and only if there is a neighbor wi of v such that i and 0 are clockwise crossing, we rotate counterclockwise by an angle β < π until θ(i)> π. After rotation it will beθ(0)< π, hence w0 and wi will be in different vertex lists. Rotating clockwise is the mirrored case.

In Fig. 3.26(a) a tree after determining the vertex positions is displayed with an arbitrary rotation angle for each vertexv and control segment lengths smaller thanrv. In Fig. 3.26(b) the rotation angle is determined as shown in Sect. 3.3.2.1 and the control segment lengths as in Sect. 3.3.2.2.

Figure 3.23: B´ezier curves

Im Dokument Constrained Graph Drawing (Seite 48-60)