3 releases

0.2.2 Sep 14, 2024
0.2.1 Sep 14, 2024
0.2.0 Sep 8, 2024
0.1.0 Sep 8, 2024

#1937 in Algorithms

47 downloads per month

Custom license

6MB
1.5K SLoC

Contains (Windows DLL, 2.5MB) SDL2.dll

RustGrapher

A library to simulate and visualize a 2D force directed graph in rust. plot

Features

  • Render PetGraphs in 2D
  • Physics based positioning via a Force Directed Graph
  • Drag Nodes to a new position
  • Place new nodes
  • WIP: Build graphs using the UI

Algorithms

Barnes–Hut

Barnes-Hut is a approximation algorithm for n-body simulation.

The force directed graph calculates for each node the repulsive force to other nodes which will lead to a complexity of $O(n^2)$.

Using a k-d Tree(Quadtree) the Barnes-Hut algorithm groups far away nodes and only calculates the repulsive force once.This results in a complexity of $O(nlogn)$.

Performance

[!TIP] Run the project with --release for the best performance(~10x).

On a Ryzen 7 3700X the library can calculate 2000 simulation steps per second at 1000 Nodes. (Using 16 Physics threads)

Controls

  • return - Centers the camera on the average poisson of all nodes.
  • space - Start/Pause simulation
  • scroll wheel - Zoom in or out
  • W, A, S and D - to move the camera
  • Click and drag - move nodes
  • P - switch from drag to node place(only works while simulation is paused)

Usage

    // Build a PetGraph
    let mut rng = rand::thread_rng();
    let graph: petgraph::Graph<(), (), Directed> =
        petgraph_gen::barabasi_albert_graph(&mut rng, 1000, 1, None);

    // Configure the simulator
    let simulator = SimulatorBuilder::new()
        .delta_time(0.01)
        .freeze_threshold(-1.0)
        .build(graph.into());

    // Start the renderer
    let renderer = Renderer::new(simulator);
    renderer.create_window();

Examples

Dependencies

~12–26MB
~388K SLoC