Circular layout algorithm for positioning graph nodes in Elixir.
Positions nodes uniformly spaced along the circumference of a circle. This layout highlights the cyclic structure of graphs and prevents node overlapping by design, making it highly suitable for symmetric networks or cycle structures.
Mathematical Model
Given a set of $N$ nodes, a circle centered at $(c_x, c_y)$ with radius $R$, the coordinates for each node $i$ (where $0 \le i < N$) are calculated using polar coordinates:
$$ \theta_i = \frac{2 \pi \cdot i}{N} $$ $$ x_i = c_x + R \cdot \cos(\theta_i) $$ $$ y_i = c_y + R \cdot \sin(\theta_i) $$
For a single-node graph ($N=1$), the node is positioned directly at the center $(c_x, c_y)$.
Complexities
- Time Complexity: $O(V)$ where $V$ is the number of nodes.
- Space Complexity: $O(V)$ auxiliary space to allocate the coordinates map.
References
Summary
Functions
Positions nodes uniformly spaced on a circle.
Functions
@spec layout( Yog.Graph.t(), keyword() ) :: %{required(Yog.Graph.node_id()) => {float(), float()}}
Positions nodes uniformly spaced on a circle.
Options
:radius- The radius of the circle (default:1.0).:center- The{x, y}coordinates of the center of the circle (default:{0.0, 0.0}).
Examples
iex> graph = Yog.undirected() |> Yog.add_nodes_from([1, 2, 3])
iex> pos = Yog.Layout.Circular.layout(graph)
iex> Map.keys(pos) |> Enum.sort()
[1, 2, 3]