sphere_layout

Contents

sphere_layout#

graph_tool.draw.sphere_layout(g, order=None, radius=1.0, pos=None)[git][source]#

Place the vertices on a sphere, approximately evenly spaced.

Parameters:
gGraph

Graph to be used.

orderiterable of int (optional, default: None)

The vertices in their order along the spiral. If not given, the order of the vertex indices is used.

radiusfloat (optional, default: 1.)

Radius of the sphere.

posVertexPropertyMap (optional, default: None)

If provided, the positions will be stored in this property map.

Returns:
posVertexPropertyMap

Vector vertex property map with the \((x, y, z)\) coordinates.

See also

circle_layout

Vertices on a circle

grid_layout

Vertices on a regular grid

random_layout

Random layout

Notes

The vertices are placed along the spiral of Saff and Kuijlaars [saff-distributing-1997], from the south to the north pole: the \(k\)-th of \(n\) vertices in the order, with \(k = 0, \dots, n - 1\), is placed at

\[\boldsymbol x_k = R\left(\sqrt{1 - h_k^2}\cos\phi_k, \sqrt{1 - h_k^2}\sin\phi_k, h_k\right),\]

where \(R\) is radius, with the height \(h_k = -1 + 2k/(n-1)\) and the azimuth \(\phi_k = \phi_{k-1} + 3.6/\sqrt{n(1 - h_k^2)} \bmod 2\pi\), with \(\phi_0 = \phi_{n-1} = 0\), so that consecutive vertices are close. (A single vertex is placed at the south pole.) The edges are ignored.

References

[saff-distributing-1997]

E. B. Saff and A. B. J. Kuijlaars, “Distributing many points on a sphere”, The Mathematical Intelligencer 19, 5-11 (1997), DOI: 10.1007/BF03024331 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> pos = gt.sphere_layout(g)
>>> print(pos[0].a, pos[33].a)
[ 0.  0. -1.] [0. 0. 1.]

The spiral can be seen in the layout of a path graph, whose edges join consecutive vertices, by drawing the projection of the southern hemisphere on the \((x, y)\) plane, as follows:

>>> g = gt.lattice([400])
>>> pos = gt.sphere_layout(g)
>>> x = pos.get_2d_array([0, 1, 2])
>>> u = gt.GraphView(g, vfilt=x[2] <= 0)
>>> xy = g.new_vp("vector<double>", vals=x[:2].T)
>>> gt.graph_draw(u, pos=xy, output="sphere-layout-path.pdf")
<...>
../_images/sphere-layout-path.png

Projection on the \((x, y)\) plane of the southern hemisphere of the sphere layout of a path graph with 400 vertices, with the south pole at the center.#